From 9d0610d4ca132e581efce63ae31b8525c8e9c179 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 5 Mar 2024 12:31:29 +0530 Subject: [PATCH 01/53] HLM-5117 codegen generated code changes --- health-services/output/README.md | 18 ++ health-services/output/pom.xml | 142 +++++++++++++ .../output/src/main/java/digit/Main.java | 20 ++ .../main/java/digit/config/Configuration.java | 92 +++++++++ .../java/digit/config/MainConfiguration.java | 39 ++++ .../java/digit/config/ServiceConstants.java | 50 +++++ .../src/main/java/digit/kafka/Consumer.java | 21 ++ .../src/main/java/digit/kafka/Producer.java | 20 ++ .../repository/ServiceRequestRepository.java | 47 +++++ .../java/digit/service/EnrichmentService.java | 53 +++++ .../service/PlanConfigurationService.java | 24 +++ .../src/main/java/digit/util/IdgenUtil.java | 55 ++++++ .../src/main/java/digit/util/MdmsUtil.java | 77 ++++++++ .../java/digit/util/ResponseInfoFactory.java | 27 +++ .../java/digit/util/UrlShortenerUtil.java | 40 ++++ .../src/main/java/digit/util/UserUtil.java | 140 +++++++++++++ .../main/java/digit/util/WorkflowUtil.java | 187 ++++++++++++++++++ .../web/controllers/ConfigApiController.java | 87 ++++++++ .../web/controllers/CreateApiController.java | 62 ++++++ .../web/controllers/SearchApiController.java | 62 ++++++ .../web/controllers/UpdateApiController.java | 62 ++++++ .../main/java/digit/web/models/Activity.java | 69 +++++++ .../java/digit/web/models/Assumption.java | 44 +++++ .../main/java/digit/web/models/Condition.java | 35 ++++ .../src/main/java/digit/web/models/Error.java | 54 +++++ .../main/java/digit/web/models/ErrorRes.java | 46 +++++ .../src/main/java/digit/web/models/File.java | 74 +++++++ .../main/java/digit/web/models/Operation.java | 88 +++++++++ .../src/main/java/digit/web/models/Plan.java | 93 +++++++++ .../digit/web/models/PlanConfiguration.java | 92 +++++++++ .../web/models/PlanConfigurationRequest.java | 34 ++++ .../web/models/PlanConfigurationResponse.java | 42 ++++ .../PlanConfigurationSearchCriteria.java | 38 ++++ .../PlanConfigurationSearchRequest.java | 33 ++++ .../digit/web/models/PlanCreateRequest.java | 33 ++++ .../digit/web/models/PlanEditRequest.java | 33 ++++ .../digit/web/models/PlanSearchCriteria.java | 38 ++++ .../digit/web/models/PlanSearchRequest.java | 33 ++++ .../digit/web/models/PlanSearchResponse.java | 42 ++++ .../main/java/digit/web/models/Resource.java | 42 ++++ .../digit/web/models/ResourceMapping.java | 34 ++++ .../main/java/digit/web/models/Target.java | 45 +++++ .../src/main/resources/application.properties | 83 ++++++++ .../output/src/main/resources/db/Dockerfile | 9 + .../output/src/main/resources/db/migrate.sh | 3 + .../test/java/digit/TestConfiguration.java | 16 ++ .../controllers/ConfigApiControllerTest.java | 72 +++++++ .../controllers/CreateApiControllerTest.java | 43 ++++ .../controllers/SearchApiControllerTest.java | 43 ++++ .../controllers/UpdateApiControllerTest.java | 43 ++++ 50 files changed, 2679 insertions(+) create mode 100644 health-services/output/README.md create mode 100644 health-services/output/pom.xml create mode 100644 health-services/output/src/main/java/digit/Main.java create mode 100644 health-services/output/src/main/java/digit/config/Configuration.java create mode 100644 health-services/output/src/main/java/digit/config/MainConfiguration.java create mode 100644 health-services/output/src/main/java/digit/config/ServiceConstants.java create mode 100644 health-services/output/src/main/java/digit/kafka/Consumer.java create mode 100644 health-services/output/src/main/java/digit/kafka/Producer.java create mode 100644 health-services/output/src/main/java/digit/repository/ServiceRequestRepository.java create mode 100644 health-services/output/src/main/java/digit/service/EnrichmentService.java create mode 100644 health-services/output/src/main/java/digit/service/PlanConfigurationService.java create mode 100644 health-services/output/src/main/java/digit/util/IdgenUtil.java create mode 100644 health-services/output/src/main/java/digit/util/MdmsUtil.java create mode 100644 health-services/output/src/main/java/digit/util/ResponseInfoFactory.java create mode 100644 health-services/output/src/main/java/digit/util/UrlShortenerUtil.java create mode 100644 health-services/output/src/main/java/digit/util/UserUtil.java create mode 100644 health-services/output/src/main/java/digit/util/WorkflowUtil.java create mode 100644 health-services/output/src/main/java/digit/web/controllers/ConfigApiController.java create mode 100644 health-services/output/src/main/java/digit/web/controllers/CreateApiController.java create mode 100644 health-services/output/src/main/java/digit/web/controllers/SearchApiController.java create mode 100644 health-services/output/src/main/java/digit/web/controllers/UpdateApiController.java create mode 100644 health-services/output/src/main/java/digit/web/models/Activity.java create mode 100644 health-services/output/src/main/java/digit/web/models/Assumption.java create mode 100644 health-services/output/src/main/java/digit/web/models/Condition.java create mode 100644 health-services/output/src/main/java/digit/web/models/Error.java create mode 100644 health-services/output/src/main/java/digit/web/models/ErrorRes.java create mode 100644 health-services/output/src/main/java/digit/web/models/File.java create mode 100644 health-services/output/src/main/java/digit/web/models/Operation.java create mode 100644 health-services/output/src/main/java/digit/web/models/Plan.java create mode 100644 health-services/output/src/main/java/digit/web/models/PlanConfiguration.java create mode 100644 health-services/output/src/main/java/digit/web/models/PlanConfigurationRequest.java create mode 100644 health-services/output/src/main/java/digit/web/models/PlanConfigurationResponse.java create mode 100644 health-services/output/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java create mode 100644 health-services/output/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java create mode 100644 health-services/output/src/main/java/digit/web/models/PlanCreateRequest.java create mode 100644 health-services/output/src/main/java/digit/web/models/PlanEditRequest.java create mode 100644 health-services/output/src/main/java/digit/web/models/PlanSearchCriteria.java create mode 100644 health-services/output/src/main/java/digit/web/models/PlanSearchRequest.java create mode 100644 health-services/output/src/main/java/digit/web/models/PlanSearchResponse.java create mode 100644 health-services/output/src/main/java/digit/web/models/Resource.java create mode 100644 health-services/output/src/main/java/digit/web/models/ResourceMapping.java create mode 100644 health-services/output/src/main/java/digit/web/models/Target.java create mode 100644 health-services/output/src/main/resources/application.properties create mode 100644 health-services/output/src/main/resources/db/Dockerfile create mode 100644 health-services/output/src/main/resources/db/migrate.sh create mode 100644 health-services/output/src/test/java/digit/TestConfiguration.java create mode 100644 health-services/output/src/test/java/digit/web/controllers/ConfigApiControllerTest.java create mode 100644 health-services/output/src/test/java/digit/web/controllers/CreateApiControllerTest.java create mode 100644 health-services/output/src/test/java/digit/web/controllers/SearchApiControllerTest.java create mode 100644 health-services/output/src/test/java/digit/web/controllers/UpdateApiControllerTest.java diff --git a/health-services/output/README.md b/health-services/output/README.md new file mode 100644 index 00000000000..a2e8a9f7b84 --- /dev/null +++ b/health-services/output/README.md @@ -0,0 +1,18 @@ +# Swagger generated server + +Spring Boot Server + + +## Overview +This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. +By using the [OpenAPI-Spec](https://github.com/swagger-api/swagger-core), you can easily generate a server stub. +This is an example of building a swagger-enabled server in Java using the SpringBoot framework. + +The underlying library integrating swagger to SpringBoot is [springfox](https://github.com/springfox/springfox) + +Start your server as an simple java application + +You can view the api documentation in swagger-ui by pointing to +http://localhost:8080/ + +Change default port value in application.properties \ No newline at end of file diff --git a/health-services/output/pom.xml b/health-services/output/pom.xml new file mode 100644 index 00000000000..40396f5d3c1 --- /dev/null +++ b/health-services/output/pom.xml @@ -0,0 +1,142 @@ + + 4.0.0 + org.egov + plan-service + jar + plan-service + 1.0.0 + + 17 + ${java.version} + ${java.version} + + + org.springframework.boot + spring-boot-starter-parent + 3.2.2 + + + src/main/java + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.flywaydb + flyway-core + 9.22.3 + + + org.postgresql + postgresql + 42.7.1 + + + org.springframework.boot + spring-boot-starter-test + test + + + + io.swagger + swagger-core + 1.5.18 + + + io.swagger.core.v3 + swagger-annotations + 2.2.8 + + + + + org.egov.services + tracer + 2.9.0-SNAPSHOT + + + + + + + + org.egov + mdms-client + 2.9.0-SNAPSHOT + compile + + + org.projectlombok + lombok + true + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + + javax.annotation + javax.annotation-api + 1.3.2 + + + javax.servlet + javax.servlet-api + 4.0.1 + provided + + + junit + junit + test + + + junit + junit + test + + + + + repo.egovernments.org + eGov ERP Releases Repository + https://nexus-repo.egovernments.org/nexus/content/repositories/releases/ + + + repo.egovernments.org.snapshots + eGov ERP Releases Repository + https://nexus-repo.egovernments.org/nexus/content/repositories/snapshots/ + + + repo.egovernments.org.public + eGov Public Repository Group + https://nexus-repo.egovernments.org/nexus/content/groups/public/ + + + repo.digit.org + eGov DIGIT Releases Repository + https://nexus-repo.digit.org/nexus/content/repositories/snapshots/ + + + diff --git a/health-services/output/src/main/java/digit/Main.java b/health-services/output/src/main/java/digit/Main.java new file mode 100644 index 00000000000..6e3d79db11c --- /dev/null +++ b/health-services/output/src/main/java/digit/Main.java @@ -0,0 +1,20 @@ +package digit; + + +import org.egov.tracer.config.TracerConfiguration; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Import; + +@Import({ TracerConfiguration.class }) +@SpringBootApplication +@ComponentScan(basePackages = { "digit", "digit.web.controllers" , "digit.config"}) +public class Main { + + + public static void main(String[] args) throws Exception { + SpringApplication.run(Main.class, args); + } + +} diff --git a/health-services/output/src/main/java/digit/config/Configuration.java b/health-services/output/src/main/java/digit/config/Configuration.java new file mode 100644 index 00000000000..d428c00d54b --- /dev/null +++ b/health-services/output/src/main/java/digit/config/Configuration.java @@ -0,0 +1,92 @@ +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; +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 javax.annotation.PostConstruct; +import java.util.TimeZone; + +@Component +@Data +@Import({TracerConfiguration.class}) +@NoArgsConstructor +@AllArgsConstructor +@Setter +@Getter +public class Configuration { + + + // User Config + @Value("${egov.user.host}") + private String userHost; + + @Value("${egov.user.context.path}") + private String userContextPath; + + @Value("${egov.user.create.path}") + private String userCreateEndpoint; + + @Value("${egov.user.search.path}") + private String userSearchEndpoint; + + @Value("${egov.user.update.path}") + private String userUpdateEndpoint; + + + //Idgen Config + @Value("${egov.idgen.host}") + private String idGenHost; + + @Value("${egov.idgen.path}") + private String idGenPath; + + + //Workflow Config + @Value("${egov.workflow.host}") + private String wfHost; + + @Value("${egov.workflow.transition.path}") + private String wfTransitionPath; + + @Value("${egov.workflow.businessservice.search.path}") + private String wfBusinessServiceSearchPath; + + @Value("${egov.workflow.processinstance.search.path}") + private String wfProcessInstanceSearchPath; + + + //MDMS + @Value("${egov.mdms.host}") + private String mdmsHost; + + @Value("${egov.mdms.search.endpoint}") + private String mdmsEndPoint; + + + //HRMS + @Value("${egov.hrms.host}") + private String hrmsHost; + + @Value("${egov.hrms.search.endpoint}") + private String hrmsEndPoint; + + + //URLShortening + @Value("${egov.url.shortner.host}") + private String urlShortnerHost; + + @Value("${egov.url.shortner.endpoint}") + private String urlShortnerEndpoint; + + + //SMSNotification + @Value("${egov.sms.notification.topic}") + private String smsNotificationTopic; +} diff --git a/health-services/output/src/main/java/digit/config/MainConfiguration.java b/health-services/output/src/main/java/digit/config/MainConfiguration.java new file mode 100644 index 00000000000..60b7660e94c --- /dev/null +++ b/health-services/output/src/main/java/digit/config/MainConfiguration.java @@ -0,0 +1,39 @@ +package digit.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import java.util.TimeZone; +import javax.annotation.PostConstruct; + import com.fasterxml.jackson.databind.DeserializationFeature; + import com.fasterxml.jackson.databind.ObjectMapper; +import org.egov.tracer.config.TracerConfiguration; + + +@Import({TracerConfiguration.class}) +public class MainConfiguration { + + @Value("${app.timezone}") + private String timeZone; + + @PostConstruct + public void initialize() { + TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); + } + + @Bean + public ObjectMapper objectMapper(){ + return new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).setTimeZone(TimeZone.getTimeZone(timeZone)); + } + + @Bean + @Autowired + public MappingJackson2HttpMessageConverter jacksonConverter(ObjectMapper objectMapper) { + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); + converter.setObjectMapper(objectMapper); + return converter; + } +} \ No newline at end of file diff --git a/health-services/output/src/main/java/digit/config/ServiceConstants.java b/health-services/output/src/main/java/digit/config/ServiceConstants.java new file mode 100644 index 00000000000..6b0c4a6f9ab --- /dev/null +++ b/health-services/output/src/main/java/digit/config/ServiceConstants.java @@ -0,0 +1,50 @@ +package digit.config; + + +import org.springframework.stereotype.Component; + + +@Component +public class ServiceConstants { + + public static final String EXTERNAL_SERVICE_EXCEPTION = "External Service threw an Exception: "; + public static final String SEARCHER_SERVICE_EXCEPTION = "Exception while fetching from searcher: "; + + public static final String IDGEN_ERROR = "IDGEN ERROR"; + public static final String NO_IDS_FOUND_ERROR = "No ids returned from idgen Service"; + + public static final String ERROR_WHILE_FETCHING_FROM_MDMS = "Exception occurred while fetching category lists from mdms: "; + + public static final String RES_MSG_ID = "uief87324"; + public static final String SUCCESSFUL = "successful"; + public static final String FAILED = "failed"; + + public static final String URL = "url"; + public static final String URL_SHORTENING_ERROR_CODE = "URL_SHORTENING_ERROR"; + public static final String URL_SHORTENING_ERROR_MESSAGE = "Unable to shorten url: "; + + public static final String DOB_FORMAT_Y_M_D = "yyyy-MM-dd"; + public static final String DOB_FORMAT_D_M_Y = "dd/MM/yyyy"; + public static final String ILLEGAL_ARGUMENT_EXCEPTION_CODE = "IllegalArgumentException"; + public static final String OBJECTMAPPER_UNABLE_TO_CONVERT = "ObjectMapper not able to convertValue in userCall"; + public static final String DOB_FORMAT_D_M_Y_H_M_S = "dd-MM-yyyy HH:mm:ss"; + public static final String CREATED_DATE = "createdDate"; + public static final String LAST_MODIFIED_DATE = "lastModifiedDate"; + public static final String DOB = "dob"; + public static final String PWD_EXPIRY_DATE = "pwdExpiryDate"; + public static final String INVALID_DATE_FORMAT_CODE = "INVALID_DATE_FORMAT"; + public static final String INVALID_DATE_FORMAT_MESSAGE = "Failed to parse date format in user"; + public static final String CITIZEN_UPPER = "CITIZEN"; + public static final String CITIZEN_LOWER = "Citizen"; + public static final String USER = "user"; + + public static final String PARSING_ERROR = "PARSING ERROR"; + public static final String FAILED_TO_PARSE_BUSINESS_SERVICE_SEARCH = "Failed to parse response of workflow business service search"; + public static final String BUSINESS_SERVICE_NOT_FOUND = "BUSINESSSERVICE_NOT_FOUND"; + public static final String THE_BUSINESS_SERVICE = "The businessService "; + public static final String NOT_FOUND = " is not found"; + public static final String TENANTID = "?tenantId="; + public static final String BUSINESS_SERVICES = "&businessServices="; + + +} diff --git a/health-services/output/src/main/java/digit/kafka/Consumer.java b/health-services/output/src/main/java/digit/kafka/Consumer.java new file mode 100644 index 00000000000..557634d78b2 --- /dev/null +++ b/health-services/output/src/main/java/digit/kafka/Consumer.java @@ -0,0 +1,21 @@ +package digit.kafka; + +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.stereotype.Component; + +import java.util.HashMap; + +@Component +public class Consumer { + + /* + * Uncomment the below line to start consuming record from kafka.topics.consumer + * Value of the variable kafka.topics.consumer should be overwritten in application.properties + */ + //@KafkaListener(topics = {"kafka.topics.consumer"}) + public void listen(final HashMap record) { + + //TODO + + } +} diff --git a/health-services/output/src/main/java/digit/kafka/Producer.java b/health-services/output/src/main/java/digit/kafka/Producer.java new file mode 100644 index 00000000000..542f4f686c0 --- /dev/null +++ b/health-services/output/src/main/java/digit/kafka/Producer.java @@ -0,0 +1,20 @@ +package digit.kafka; + +import lombok.extern.slf4j.Slf4j; +import org.egov.tracer.kafka.CustomKafkaTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +// NOTE: If tracer is disabled change CustomKafkaTemplate to KafkaTemplate in autowiring + +@Service +@Slf4j +public class Producer { + + @Autowired + private CustomKafkaTemplate kafkaTemplate; + + public void push(String topic, Object value) { + kafkaTemplate.send(topic, value); + } +} diff --git a/health-services/output/src/main/java/digit/repository/ServiceRequestRepository.java b/health-services/output/src/main/java/digit/repository/ServiceRequestRepository.java new file mode 100644 index 00000000000..7a2ebeeca71 --- /dev/null +++ b/health-services/output/src/main/java/digit/repository/ServiceRequestRepository.java @@ -0,0 +1,47 @@ +package digit.repository; + + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import lombok.extern.slf4j.Slf4j; +import org.egov.tracer.model.ServiceCallException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; + +import java.util.Map; + +import static digit.config.ServiceConstants.*; + +@Repository +@Slf4j +public class ServiceRequestRepository { + + private ObjectMapper mapper; + + private RestTemplate restTemplate; + + + @Autowired + public ServiceRequestRepository(ObjectMapper mapper, RestTemplate restTemplate) { + this.mapper = mapper; + this.restTemplate = restTemplate; + } + + + public Object fetchResult(StringBuilder uri, Object request) { + mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + Object response = null; + try { + response = restTemplate.postForObject(uri.toString(), request, Map.class); + } catch (HttpClientErrorException e) { + log.error(EXTERNAL_SERVICE_EXCEPTION, e); + throw new ServiceCallException(e.getResponseBodyAsString()); + } catch (Exception e) { + log.error(SEARCHER_SERVICE_EXCEPTION, e); + } + + return response; + } +} \ No newline at end of file diff --git a/health-services/output/src/main/java/digit/service/EnrichmentService.java b/health-services/output/src/main/java/digit/service/EnrichmentService.java new file mode 100644 index 00000000000..633e24a1c62 --- /dev/null +++ b/health-services/output/src/main/java/digit/service/EnrichmentService.java @@ -0,0 +1,53 @@ +package digit.service; + +import digit.config.Configuration; +import digit.config.ServiceConstants; +import digit.util.IdgenUtil; +import digit.web.models.Assumption; +import digit.web.models.Operation; +import digit.web.models.PlanConfiguration; +import digit.web.models.PlanConfigurationRequest; +import java.util.List; +import java.util.UUID; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + + +@Service +@Slf4j +public class EnrichmentService { + + private final IdgenUtil idgenUtil; + + private final Configuration config; + + public EnrichmentService(IdgenUtil idgenUtil, Configuration config) { + this.idgenUtil = idgenUtil; + this.config = config; + } + + public void create(PlanConfigurationRequest request) throws Exception { + enrichPlanConfiguration(request.getPlanConfiguration()); + + log.info("enriching facility enrichment with generated IDs"); + } + + public static PlanConfiguration enrichPlanConfiguration(PlanConfiguration planConfiguration) { + // Set ID for PlanConfiguration + planConfiguration.setId(UUID.randomUUID()); + + // Set IDs for Assumptions + List assumptions = planConfiguration.getAssumptions(); + for (Assumption assumption : assumptions) { + assumption.setId(UUID.randomUUID()); + } + + // Set IDs for Operations + List operations = planConfiguration.getOperations(); + for (Operation operation : operations) { + operation.setId(UUID.randomUUID()); + } + + return planConfiguration; + } +} diff --git a/health-services/output/src/main/java/digit/service/PlanConfigurationService.java b/health-services/output/src/main/java/digit/service/PlanConfigurationService.java new file mode 100644 index 00000000000..39242237fb9 --- /dev/null +++ b/health-services/output/src/main/java/digit/service/PlanConfigurationService.java @@ -0,0 +1,24 @@ +package digit.service; + +import digit.web.models.PlanConfiguration; +import digit.web.models.PlanConfigurationRequest; +import java.util.List; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class PlanConfigurationService { + + @Autowired + public PlanConfigurationService() { + } + + public PlanConfigurationRequest create(PlanConfigurationRequest request) { + log.info("received request to create plan configurations"); + + return new PlanConfigurationRequest(); + } +} \ No newline at end of file diff --git a/health-services/output/src/main/java/digit/util/IdgenUtil.java b/health-services/output/src/main/java/digit/util/IdgenUtil.java new file mode 100644 index 00000000000..5e4a18c199c --- /dev/null +++ b/health-services/output/src/main/java/digit/util/IdgenUtil.java @@ -0,0 +1,55 @@ +package digit.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import digit.repository.ServiceRequestRepository; +import digit.config.Configuration; +//import digit.models.coremodels.IdGenerationRequest; +//import digit.models.coremodels.IdGenerationResponse; +//import digit.models.coremodels.IdRequest; +//import digit.models.coremodels.IdResponse; +import org.egov.common.contract.idgen.IdGenerationRequest; +import org.egov.common.contract.idgen.IdGenerationResponse; +import org.egov.common.contract.idgen.IdRequest; +import org.egov.common.contract.idgen.IdResponse; +import org.egov.common.contract.request.RequestInfo; +import org.egov.tracer.model.CustomException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static digit.config.ServiceConstants.*; + +@Component +public class IdgenUtil { + + @Autowired + private ObjectMapper mapper; + + @Autowired + private ServiceRequestRepository restRepo; + + @Autowired + private Configuration configs; + + public List getIdList(RequestInfo requestInfo, String tenantId, String idName, String idformat, Integer count) { + List reqList = new ArrayList<>(); + for (int i = 0; i < count; i++) { + reqList.add(IdRequest.builder().idName(idName).format(idformat).tenantId(tenantId).build()); + } + + IdGenerationRequest request = IdGenerationRequest.builder().idRequests(reqList).requestInfo(requestInfo).build(); + StringBuilder uri = new StringBuilder(configs.getIdGenHost()).append(configs.getIdGenPath()); + IdGenerationResponse response = mapper.convertValue(restRepo.fetchResult(uri, request), IdGenerationResponse.class); + + List idResponses = response.getIdResponses(); + + if (CollectionUtils.isEmpty(idResponses)) + throw new CustomException(IDGEN_ERROR, NO_IDS_FOUND_ERROR); + + return idResponses.stream().map(IdResponse::getId).collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/health-services/output/src/main/java/digit/util/MdmsUtil.java b/health-services/output/src/main/java/digit/util/MdmsUtil.java new file mode 100644 index 00000000000..69fa8e26f03 --- /dev/null +++ b/health-services/output/src/main/java/digit/util/MdmsUtil.java @@ -0,0 +1,77 @@ +package digit.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import digit.config.Configuration; +import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.request.RequestInfo; +import org.egov.mdms.model.*; + +import org.json.JSONArray; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static digit.config.ServiceConstants.*; + +@Slf4j +@Component +public class MdmsUtil { + + @Autowired + private RestTemplate restTemplate; + + @Autowired + private ObjectMapper mapper; + + @Autowired + private Configuration configs; + + + public Object fetchMdmsData(RequestInfo requestInfo, String tenantId, String moduleName, List masterNameList) { + StringBuilder uri = new StringBuilder(); + uri.append(configs.getMdmsHost()).append(configs.getMdmsEndPoint()); + MdmsCriteriaReq mdmsCriteriaReq = getMdmsRequest(requestInfo, tenantId, moduleName, masterNameList); + Object response = new HashMap<>(); + Integer rate = 0; + MdmsResponse mdmsResponse = new MdmsResponse(); + try { + response = restTemplate.postForObject(uri.toString(), mdmsCriteriaReq, Map.class); + mdmsResponse = mapper.convertValue(response, MdmsResponse.class); + } catch (Exception e) { + log.error(ERROR_WHILE_FETCHING_FROM_MDMS, e); + } + + return mdmsResponse.getMdmsRes(); + //log.info(ulbToCategoryListMap.toString()); + } + + private MdmsCriteriaReq getMdmsRequest(RequestInfo requestInfo, String tenantId, String moduleName, List masterNameList) { + List masterDetailList = new ArrayList<>(); + for (String masterName : masterNameList) { + MasterDetail masterDetail = new MasterDetail(); + masterDetail.setName(masterName); + masterDetailList.add(masterDetail); + } + + ModuleDetail moduleDetail = new ModuleDetail(); + moduleDetail.setMasterDetails(masterDetailList); + moduleDetail.setModuleName(moduleName); + List moduleDetailList = new ArrayList<>(); + moduleDetailList.add(moduleDetail); + + MdmsCriteria mdmsCriteria = new MdmsCriteria(); + mdmsCriteria.setTenantId(tenantId.split("\\.")[0]); + mdmsCriteria.setModuleDetails(moduleDetailList); + + MdmsCriteriaReq mdmsCriteriaReq = new MdmsCriteriaReq(); + mdmsCriteriaReq.setMdmsCriteria(mdmsCriteria); + mdmsCriteriaReq.setRequestInfo(requestInfo); + + return mdmsCriteriaReq; + } +} \ No newline at end of file diff --git a/health-services/output/src/main/java/digit/util/ResponseInfoFactory.java b/health-services/output/src/main/java/digit/util/ResponseInfoFactory.java new file mode 100644 index 00000000000..829ee470566 --- /dev/null +++ b/health-services/output/src/main/java/digit/util/ResponseInfoFactory.java @@ -0,0 +1,27 @@ +package digit.util; + +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.stereotype.Component; + +import static digit.config.ServiceConstants.*; + +@Component +public class ResponseInfoFactory { + + public ResponseInfo createResponseInfoFromRequestInfo(final RequestInfo requestInfo, final Boolean success) { + + final String apiId = requestInfo != null ? requestInfo.getApiId() : ""; + final String ver = requestInfo != null ? requestInfo.getVer() : ""; + Long ts = null; + if (requestInfo != null) + ts = requestInfo.getTs(); + final String resMsgId = RES_MSG_ID; // FIXME : Hard-coded + final String msgId = requestInfo != null ? requestInfo.getMsgId() : ""; + final String responseStatus = success ? SUCCESSFUL : FAILED; + + return ResponseInfo.builder().apiId(apiId).ver(ver).ts(ts).resMsgId(resMsgId).msgId(msgId).resMsgId(resMsgId) + .status(responseStatus).build(); + } + +} \ No newline at end of file diff --git a/health-services/output/src/main/java/digit/util/UrlShortenerUtil.java b/health-services/output/src/main/java/digit/util/UrlShortenerUtil.java new file mode 100644 index 00000000000..26c9c0048a1 --- /dev/null +++ b/health-services/output/src/main/java/digit/util/UrlShortenerUtil.java @@ -0,0 +1,40 @@ +package digit.util; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; +import java.util.HashMap; +import digit.config.Configuration; + +import static digit.config.ServiceConstants.*; + +@Slf4j +@Component +public class UrlShortenerUtil { + + @Autowired + private RestTemplate restTemplate; + + @Autowired + private Configuration configs; + + + public String getShortenedUrl(String url) { + + HashMap body = new HashMap<>(); + body.put(URL, url); + StringBuilder builder = new StringBuilder(configs.getUrlShortnerHost()); + builder.append(configs.getUrlShortnerEndpoint()); + String res = restTemplate.postForObject(builder.toString(), body, String.class); + + if (StringUtils.isEmpty(res)) { + log.error(URL_SHORTENING_ERROR_CODE, URL_SHORTENING_ERROR_MESSAGE + url); + ; + return url; + } else return res; + } + + +} \ No newline at end of file diff --git a/health-services/output/src/main/java/digit/util/UserUtil.java b/health-services/output/src/main/java/digit/util/UserUtil.java new file mode 100644 index 00000000000..5a4c14e44a6 --- /dev/null +++ b/health-services/output/src/main/java/digit/util/UserUtil.java @@ -0,0 +1,140 @@ +package digit.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import digit.config.Configuration; + +import static digit.config.ServiceConstants.*; + +import digit.repository.ServiceRequestRepository; +import org.egov.common.contract.request.Role; +import org.egov.common.contract.request.User; +import org.egov.common.contract.user.UserDetailResponse; +import org.egov.common.contract.user.enums.UserType; +import org.egov.tracer.model.CustomException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +@Component +public class UserUtil { + + @Autowired + private ObjectMapper mapper; + + @Autowired + private ServiceRequestRepository serviceRequestRepository; + + @Autowired + private Configuration configs; + + + @Autowired + public UserUtil(ObjectMapper mapper, ServiceRequestRepository serviceRequestRepository) { + this.mapper = mapper; + this.serviceRequestRepository = serviceRequestRepository; + } + + /** + * Returns UserDetailResponse by calling user service with given uri and object + * + * @param userRequest Request object for user service + * @param uri The address of the endpoint + * @return Response from user service as parsed as userDetailResponse + */ + + public UserDetailResponse userCall(Object userRequest, StringBuilder uri) { + String dobFormat = null; + if (uri.toString().contains(configs.getUserSearchEndpoint()) || uri.toString().contains(configs.getUserUpdateEndpoint())) + dobFormat = DOB_FORMAT_Y_M_D; + else if (uri.toString().contains(configs.getUserCreateEndpoint())) + dobFormat = DOB_FORMAT_D_M_Y; + try { + LinkedHashMap responseMap = (LinkedHashMap) serviceRequestRepository.fetchResult(uri, userRequest); + parseResponse(responseMap, dobFormat); + UserDetailResponse userDetailResponse = mapper.convertValue(responseMap, UserDetailResponse.class); + return userDetailResponse; + } catch (IllegalArgumentException e) { + throw new CustomException(ILLEGAL_ARGUMENT_EXCEPTION_CODE, OBJECTMAPPER_UNABLE_TO_CONVERT); + } + } + + + /** + * Parses date formats to long for all users in responseMap + * + * @param responseMap LinkedHashMap got from user api response + */ + + public void parseResponse(LinkedHashMap responseMap, String dobFormat) { + List users = (List) responseMap.get(USER); + String format1 = DOB_FORMAT_D_M_Y_H_M_S; + if (users != null) { + users.forEach(map -> { + map.put(CREATED_DATE, dateTolong((String) map.get(CREATED_DATE), format1)); + if ((String) map.get(LAST_MODIFIED_DATE) != null) + map.put(LAST_MODIFIED_DATE, dateTolong((String) map.get(LAST_MODIFIED_DATE), format1)); + if ((String) map.get(DOB) != null) + map.put(DOB, dateTolong((String) map.get(DOB), dobFormat)); + if ((String) map.get(PWD_EXPIRY_DATE) != null) + map.put(PWD_EXPIRY_DATE, dateTolong((String) map.get(PWD_EXPIRY_DATE), format1)); + } + ); + } + } + + /** + * Converts date to long + * + * @param date date to be parsed + * @param format Format of the date + * @return Long value of date + */ + private Long dateTolong(String date, String format) { + SimpleDateFormat f = new SimpleDateFormat(format); + Date d = null; + try { + d = f.parse(date); + } catch (ParseException e) { + throw new CustomException(INVALID_DATE_FORMAT_CODE, INVALID_DATE_FORMAT_MESSAGE); + } + return d.getTime(); + } + + /** + * enriches the userInfo with statelevel tenantId and other fields + * The function creates user with username as mobile number. + * + * @param mobileNumber + * @param tenantId + * @param userInfo + */ + public void addUserDefaultFields(String mobileNumber, String tenantId, User userInfo, UserType userType) { + Role role = getCitizenRole(tenantId); + userInfo.setRoles(Collections.singletonList(role)); + userInfo.setType(String.valueOf(userType)); + userInfo.setUserName(mobileNumber); + userInfo.setTenantId(getStateLevelTenant(tenantId)); + } + + /** + * Returns role object for citizen + * + * @param tenantId + * @return + */ + private Role getCitizenRole(String tenantId) { + Role role = Role.builder().build(); + role.setCode(CITIZEN_UPPER); + role.setName(CITIZEN_LOWER); + role.setTenantId(getStateLevelTenant(tenantId)); + return role; + } + + public String getStateLevelTenant(String tenantId) { + return tenantId.split("\\.")[0]; + } + +} \ No newline at end of file diff --git a/health-services/output/src/main/java/digit/util/WorkflowUtil.java b/health-services/output/src/main/java/digit/util/WorkflowUtil.java new file mode 100644 index 00000000000..e098fb9751b --- /dev/null +++ b/health-services/output/src/main/java/digit/util/WorkflowUtil.java @@ -0,0 +1,187 @@ +package digit.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import digit.config.Configuration; + +import static digit.config.ServiceConstants.*; + +import org.egov.common.contract.models.RequestInfoWrapper; +import org.egov.common.contract.models.Workflow; +import org.egov.common.contract.request.RequestInfo; +import org.egov.common.contract.request.User; +import digit.repository.ServiceRequestRepository; +import org.egov.common.contract.workflow.BusinessService; +import org.egov.common.contract.workflow.BusinessServiceResponse; +import org.egov.common.contract.workflow.ProcessInstance; +import org.egov.common.contract.workflow.ProcessInstanceRequest; +import org.egov.common.contract.workflow.ProcessInstanceResponse; +import org.egov.common.contract.workflow.State; +import org.egov.tracer.model.CustomException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.*; +import java.util.stream.Collectors; + +@Service +public class WorkflowUtil { + + @Autowired + private ServiceRequestRepository repository; + + @Autowired + private ObjectMapper mapper; + + @Autowired + private Configuration configs; + + + /** + * Searches the BussinessService corresponding to the businessServiceCode + * Returns applicable BussinessService for the given parameters + * + * @param requestInfo + * @param tenantId + * @param businessServiceCode + * @return + */ + public BusinessService getBusinessService(RequestInfo requestInfo, String tenantId, String businessServiceCode) { + + StringBuilder url = getSearchURLWithParams(tenantId, businessServiceCode); + RequestInfoWrapper requestInfoWrapper = RequestInfoWrapper.builder().requestInfo(requestInfo).build(); + Object result = repository.fetchResult(url, requestInfoWrapper); + BusinessServiceResponse response = null; + try { + response = mapper.convertValue(result, BusinessServiceResponse.class); + } catch (IllegalArgumentException e) { + throw new CustomException(PARSING_ERROR, FAILED_TO_PARSE_BUSINESS_SERVICE_SEARCH); + } + + if (CollectionUtils.isEmpty(response.getBusinessServices())) + throw new CustomException(BUSINESS_SERVICE_NOT_FOUND, THE_BUSINESS_SERVICE + businessServiceCode + NOT_FOUND); + + return response.getBusinessServices().get(0); + } + + /** + * Calls the workflow service with the given action and updates the status + * Returns the updated status of the application + * + * @param requestInfo + * @param tenantId + * @param businessId + * @param businessServiceCode + * @param workflow + * @param wfModuleName + * @return + */ + public String updateWorkflowStatus(RequestInfo requestInfo, String tenantId, + String businessId, String businessServiceCode, Workflow workflow, String wfModuleName) { + ProcessInstance processInstance = getProcessInstanceForWorkflow(requestInfo, tenantId, businessId, + businessServiceCode, workflow, wfModuleName); + ProcessInstanceRequest workflowRequest = new ProcessInstanceRequest(requestInfo, Collections.singletonList(processInstance)); + State state = callWorkFlow(workflowRequest); + + return state.getApplicationStatus(); + } + + /** + * Creates url for search based on given tenantId and businessServices + * + * @param tenantId + * @param businessService + * @return + */ + private StringBuilder getSearchURLWithParams(String tenantId, String businessService) { + StringBuilder url = new StringBuilder(configs.getWfHost()); + url.append(configs.getWfBusinessServiceSearchPath()); + url.append(TENANTID); + url.append(tenantId); + url.append(BUSINESS_SERVICES); + url.append(businessService); + return url; + } + + /** + * Enriches ProcessInstance Object for Workflow + * + * @param requestInfo + * @param tenantId + * @param businessId + * @param businessServiceCode + * @param workflow + * @param wfModuleName + * @return + */ + private ProcessInstance getProcessInstanceForWorkflow(RequestInfo requestInfo, String tenantId, + String businessId, String businessServiceCode, Workflow workflow, String wfModuleName) { + + ProcessInstance processInstance = new ProcessInstance(); + processInstance.setBusinessId(businessId); + processInstance.setAction(workflow.getAction()); + processInstance.setModuleName(wfModuleName); + processInstance.setTenantId(tenantId); + processInstance.setBusinessService(getBusinessService(requestInfo, tenantId, businessServiceCode).getBusinessService()); + processInstance.setDocuments(workflow.getDocuments()); + processInstance.setComment(workflow.getComments()); + + if (!CollectionUtils.isEmpty(workflow.getAssignes())) { + List users = new ArrayList<>(); + + workflow.getAssignes().forEach(uuid -> { + User user = new User(); + user.setUuid(uuid); + users.add(user); + }); + + processInstance.setAssignes(users); + } + + return processInstance; + } + + /** + * Gets the workflow corresponding to the processInstance + * + * @param processInstances + * @return + */ + public Map getWorkflow(List processInstances) { + + Map businessIdToWorkflow = new HashMap<>(); + + processInstances.forEach(processInstance -> { + List userIds = null; + + if (!CollectionUtils.isEmpty(processInstance.getAssignes())) { + userIds = processInstance.getAssignes().stream().map(User::getUuid).collect(Collectors.toList()); + } + + Workflow workflow = Workflow.builder() + .action(processInstance.getAction()) + .assignes(userIds) + .comments(processInstance.getComment()) + .documents(processInstance.getDocuments()) + .build(); + + businessIdToWorkflow.put(processInstance.getBusinessId(), workflow); + }); + + return businessIdToWorkflow; + } + + /** + * Method to take the ProcessInstanceRequest as parameter and set resultant status + * + * @param workflowReq + * @return + */ + private State callWorkFlow(ProcessInstanceRequest workflowReq) { + ProcessInstanceResponse response = null; + StringBuilder url = new StringBuilder(configs.getWfHost().concat(configs.getWfTransitionPath())); + Object optional = repository.fetchResult(url, workflowReq); + response = mapper.convertValue(optional, ProcessInstanceResponse.class); + return response.getProcessInstances().get(0).getState(); + } +} \ No newline at end of file diff --git a/health-services/output/src/main/java/digit/web/controllers/ConfigApiController.java b/health-services/output/src/main/java/digit/web/controllers/ConfigApiController.java new file mode 100644 index 00000000000..69b1edb71c0 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/controllers/ConfigApiController.java @@ -0,0 +1,87 @@ +package digit.web.controllers; + + +import digit.service.PlanConfigurationService; +import digit.web.models.PlanConfigurationRequest; +import digit.web.models.PlanConfigurationResponse; +import digit.web.models.PlanConfigurationSearchRequest; +import javax.validation.Valid; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.servlet.http.HttpServletRequest; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestMapping; +import java.io.IOException; +import java.util.*; + +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Controller +@RequestMapping("/plan") +public class ConfigApiController { + + private final ObjectMapper objectMapper; + + private final HttpServletRequest request; + + private final PlanConfigurationService planConfigurationService; + + @Autowired + public ConfigApiController(ObjectMapper objectMapper, HttpServletRequest request, PlanConfigurationService planConfigurationService) { + this.objectMapper = objectMapper; + this.request = request; + this.planConfigurationService = planConfigurationService; + } + + @RequestMapping(value = "/config/_create", method = RequestMethod.POST) + public ResponseEntity configCreatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationRequest body) { + String accept = request.getHeader("Accept"); + if (accept != null && accept.contains("application/json")) { + PlanConfigurationRequest planConfigurationRequest = planConfigurationService.create(body); + PlanConfigurationResponse response = PlanConfigurationResponse.builder() + .planConfigurationResponse(Collections.singletonList(planConfigurationRequest.getPlanConfiguration())) + .responseInfo(new ResponseInfo()) + .build(); + + return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); + + } + + return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); + } + + @RequestMapping(value = "/config/_search", method = RequestMethod.POST) + public ResponseEntity configSearchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationSearchRequest body) { + String accept = request.getHeader("Accept"); + if (accept != null && accept.contains("application/json")) { + try { + return new ResponseEntity(objectMapper.readValue("{ \"ResponseInfo\" : { \"ver\" : \"ver\", \"resMsgId\" : \"resMsgId\", \"msgId\" : \"msgId\", \"apiId\" : \"apiId\", \"ts\" : 0, \"status\" : \"SUCCESSFUL\" }, \"PlanConfigurationResponse\" : [ { \"executionPlanId\" : \"executionPlanId\", \"operations\" : [ { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" }, { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" } ], \"resourceMapping\" : [ { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" }, { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" } ], \"tenantId\" : \"tenantId\", \"name\" : \"name\", \"files\" : [ { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"assumptions\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" } ] }, { \"executionPlanId\" : \"executionPlanId\", \"operations\" : [ { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" }, { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" } ], \"resourceMapping\" : [ { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" }, { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" } ], \"tenantId\" : \"tenantId\", \"name\" : \"name\", \"files\" : [ { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"assumptions\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" } ] } ]}", PlanConfigurationResponse.class), HttpStatus.NOT_IMPLEMENTED); + } catch (IOException e) { + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); + } + + @RequestMapping(value = "/config/_update", method = RequestMethod.POST) + public ResponseEntity configUpdatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationRequest body) { + String accept = request.getHeader("Accept"); + if (accept != null && accept.contains("application/json")) { + try { + return new ResponseEntity(objectMapper.readValue("{ \"ResponseInfo\" : { \"ver\" : \"ver\", \"resMsgId\" : \"resMsgId\", \"msgId\" : \"msgId\", \"apiId\" : \"apiId\", \"ts\" : 0, \"status\" : \"SUCCESSFUL\" }, \"PlanConfigurationResponse\" : [ { \"executionPlanId\" : \"executionPlanId\", \"operations\" : [ { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" }, { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" } ], \"resourceMapping\" : [ { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" }, { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" } ], \"tenantId\" : \"tenantId\", \"name\" : \"name\", \"files\" : [ { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"assumptions\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" } ] }, { \"executionPlanId\" : \"executionPlanId\", \"operations\" : [ { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" }, { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" } ], \"resourceMapping\" : [ { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" }, { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" } ], \"tenantId\" : \"tenantId\", \"name\" : \"name\", \"files\" : [ { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"assumptions\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" } ] } ]}", PlanConfigurationResponse.class), HttpStatus.NOT_IMPLEMENTED); + } catch (IOException e) { + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); + } +} diff --git a/health-services/output/src/main/java/digit/web/controllers/CreateApiController.java b/health-services/output/src/main/java/digit/web/controllers/CreateApiController.java new file mode 100644 index 00000000000..1e1ee102d8a --- /dev/null +++ b/health-services/output/src/main/java/digit/web/controllers/CreateApiController.java @@ -0,0 +1,62 @@ +package digit.web.controllers; + + +import digit.web.models.ErrorRes; +import digit.web.models.PlanCreateRequest; +import digit.web.models.PlanSearchResponse; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.bind.annotation.RequestMapping; +import java.io.IOException; +import java.util.*; + +import javax.validation.constraints.*; +import javax.validation.Valid; +import javax.servlet.http.HttpServletRequest; +import java.util.Optional; + +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Controller +@RequestMapping("/plan") +public class CreateApiController { + + private final ObjectMapper objectMapper; + + private final HttpServletRequest request; + + @Autowired + public CreateApiController(ObjectMapper objectMapper, HttpServletRequest request) { + this.objectMapper = objectMapper; + this.request = request; + } + + @RequestMapping(value = "/_create", method = RequestMethod.POST) + public ResponseEntity createPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanCreateRequest body) { + String accept = request.getHeader("Accept"); + if (accept != null && accept.contains("application/json")) { + try { + return new ResponseEntity(objectMapper.readValue("{ \"ResponseInfo\" : { \"ver\" : \"ver\", \"resMsgId\" : \"resMsgId\", \"msgId\" : \"msgId\", \"apiId\" : \"apiId\", \"ts\" : 0, \"status\" : \"SUCCESSFUL\" }, \"Plan\" : [ { \"executionPlanId\" : \"executionPlanId\", \"planConfigurationId\" : \"planConfigurationId\", \"activities\" : [ { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] }, { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] } ], \"tenantId\" : \"tenantId\", \"locality\" : \"locality\", \"resources\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"additionalDetails\" : { }, \"targets\" : [ { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ] }, { \"executionPlanId\" : \"executionPlanId\", \"planConfigurationId\" : \"planConfigurationId\", \"activities\" : [ { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] }, { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] } ], \"tenantId\" : \"tenantId\", \"locality\" : \"locality\", \"resources\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"additionalDetails\" : { }, \"targets\" : [ { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ] } ]}", PlanSearchResponse.class), HttpStatus.NOT_IMPLEMENTED); + } catch (IOException e) { + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); + } + +} diff --git a/health-services/output/src/main/java/digit/web/controllers/SearchApiController.java b/health-services/output/src/main/java/digit/web/controllers/SearchApiController.java new file mode 100644 index 00000000000..271632ccaf4 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/controllers/SearchApiController.java @@ -0,0 +1,62 @@ +package digit.web.controllers; + + +import digit.web.models.ErrorRes; +import digit.web.models.PlanSearchRequest; +import digit.web.models.PlanSearchResponse; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.bind.annotation.RequestMapping; +import java.io.IOException; +import java.util.*; + +import javax.validation.constraints.*; +import javax.validation.Valid; +import javax.servlet.http.HttpServletRequest; +import java.util.Optional; + +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Controller +@RequestMapping("/plan") +public class SearchApiController { + + private final ObjectMapper objectMapper; + + private final HttpServletRequest request; + + @Autowired + public SearchApiController(ObjectMapper objectMapper, HttpServletRequest request) { + this.objectMapper = objectMapper; + this.request = request; + } + + @RequestMapping(value = "/_search", method = RequestMethod.POST) + public ResponseEntity searchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanSearchRequest body) { + String accept = request.getHeader("Accept"); + if (accept != null && accept.contains("application/json")) { + try { + return new ResponseEntity(objectMapper.readValue("{ \"ResponseInfo\" : { \"ver\" : \"ver\", \"resMsgId\" : \"resMsgId\", \"msgId\" : \"msgId\", \"apiId\" : \"apiId\", \"ts\" : 0, \"status\" : \"SUCCESSFUL\" }, \"Plan\" : [ { \"executionPlanId\" : \"executionPlanId\", \"planConfigurationId\" : \"planConfigurationId\", \"activities\" : [ { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] }, { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] } ], \"tenantId\" : \"tenantId\", \"locality\" : \"locality\", \"resources\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"additionalDetails\" : { }, \"targets\" : [ { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ] }, { \"executionPlanId\" : \"executionPlanId\", \"planConfigurationId\" : \"planConfigurationId\", \"activities\" : [ { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] }, { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] } ], \"tenantId\" : \"tenantId\", \"locality\" : \"locality\", \"resources\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"additionalDetails\" : { }, \"targets\" : [ { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ] } ]}", PlanSearchResponse.class), HttpStatus.NOT_IMPLEMENTED); + } catch (IOException e) { + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); + } + +} diff --git a/health-services/output/src/main/java/digit/web/controllers/UpdateApiController.java b/health-services/output/src/main/java/digit/web/controllers/UpdateApiController.java new file mode 100644 index 00000000000..b8ba48f5d3a --- /dev/null +++ b/health-services/output/src/main/java/digit/web/controllers/UpdateApiController.java @@ -0,0 +1,62 @@ +package digit.web.controllers; + + +import digit.web.models.ErrorRes; +import digit.web.models.PlanEditRequest; +import digit.web.models.PlanSearchResponse; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.bind.annotation.RequestMapping; +import java.io.IOException; +import java.util.*; + +import javax.validation.constraints.*; +import javax.validation.Valid; +import javax.servlet.http.HttpServletRequest; +import java.util.Optional; + +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Controller +@RequestMapping("/plan") +public class UpdateApiController { + + private final ObjectMapper objectMapper; + + private final HttpServletRequest request; + + @Autowired + public UpdateApiController(ObjectMapper objectMapper, HttpServletRequest request) { + this.objectMapper = objectMapper; + this.request = request; + } + + @RequestMapping(value = "/_update", method = RequestMethod.POST) + public ResponseEntity updatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanEditRequest body) { + String accept = request.getHeader("Accept"); + if (accept != null && accept.contains("application/json")) { + try { + return new ResponseEntity(objectMapper.readValue("{ \"ResponseInfo\" : { \"ver\" : \"ver\", \"resMsgId\" : \"resMsgId\", \"msgId\" : \"msgId\", \"apiId\" : \"apiId\", \"ts\" : 0, \"status\" : \"SUCCESSFUL\" }, \"Plan\" : [ { \"executionPlanId\" : \"executionPlanId\", \"planConfigurationId\" : \"planConfigurationId\", \"activities\" : [ { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] }, { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] } ], \"tenantId\" : \"tenantId\", \"locality\" : \"locality\", \"resources\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"additionalDetails\" : { }, \"targets\" : [ { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ] }, { \"executionPlanId\" : \"executionPlanId\", \"planConfigurationId\" : \"planConfigurationId\", \"activities\" : [ { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] }, { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] } ], \"tenantId\" : \"tenantId\", \"locality\" : \"locality\", \"resources\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"additionalDetails\" : { }, \"targets\" : [ { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ] } ]}", PlanSearchResponse.class), HttpStatus.NOT_IMPLEMENTED); + } catch (IOException e) { + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); + } + +} diff --git a/health-services/output/src/main/java/digit/web/models/Activity.java b/health-services/output/src/main/java/digit/web/models/Activity.java new file mode 100644 index 00000000000..64d920a0f88 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/Activity.java @@ -0,0 +1,69 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import digit.web.models.Condition; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.ArrayList; +import java.util.List; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * Activity + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Activity { + @JsonProperty("id") + private String id = null; + + @JsonProperty("tenantId") + private String tenantId = null; + + @JsonProperty("description") + private String description = null; + + @JsonProperty("plannedStartDate") + private Long plannedStartDate = null; + + @JsonProperty("plannedEndDate") + private Long plannedEndDate = null; + + @JsonProperty("dependencies") + private List dependencies = null; + + @JsonProperty("resourceId") + private String resourceId = null; + + @JsonProperty("conditions") + @Valid + private List conditions = null; + + public Activity addDependenciesItem(String dependenciesItem) { + if (this.dependencies == null) { + this.dependencies = new ArrayList<>(); + } + this.dependencies.add(dependenciesItem); + return this; + } + + public Activity addConditionsItem(Condition conditionsItem) { + if (this.conditions == null) { + this.conditions = new ArrayList<>(); + } + this.conditions.add(conditionsItem); + return this; + } + +} diff --git a/health-services/output/src/main/java/digit/web/models/Assumption.java b/health-services/output/src/main/java/digit/web/models/Assumption.java new file mode 100644 index 00000000000..42855f8221d --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/Assumption.java @@ -0,0 +1,44 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.v3.oas.annotations.media.Schema; +import java.math.BigDecimal; +import java.util.UUID; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * Assumption + */ +@Validated +//@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Assumption { + @JsonProperty("id") + + @Valid + private UUID id = null; + + @JsonProperty("key") + @NotNull + + @Size(min=1,max=32) private String key = null; + + @JsonProperty("value") + @NotNull + + @Valid + private BigDecimal value = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/Condition.java b/health-services/output/src/main/java/digit/web/models/Condition.java new file mode 100644 index 00000000000..500cac71ca1 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/Condition.java @@ -0,0 +1,35 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.v3.oas.annotations.media.Schema; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * Condition + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Condition { + @JsonProperty("entity") + private String entity = null; + + @JsonProperty("entityProperty") + private String entityProperty = null; + + @JsonProperty("expression") + private String expression = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/Error.java b/health-services/output/src/main/java/digit/web/models/Error.java new file mode 100644 index 00000000000..b83266d0b25 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/Error.java @@ -0,0 +1,54 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.ArrayList; +import java.util.List; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * Error object will be returned as a part of reponse body in conjunction with ResponseInfo as part of ErrorResponse whenever the request processing status in the ResponseInfo is FAILED. HTTP return in this scenario will usually be HTTP 400. + */ +@Schema(description = "Error object will be returned as a part of reponse body in conjunction with ResponseInfo as part of ErrorResponse whenever the request processing status in the ResponseInfo is FAILED. HTTP return in this scenario will usually be HTTP 400.") +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Error { + @JsonProperty("code") + @NotNull + private String code = null; + + @JsonProperty("message") + @NotNull + + private String message = null; + + @JsonProperty("description") + + private String description = null; + + @JsonProperty("params") + + private List params = null; + + + public Error addParamsItem(String paramsItem) { + if (this.params == null) { + this.params = new ArrayList<>(); + } + this.params.add(paramsItem); + return this; + } + +} diff --git a/health-services/output/src/main/java/digit/web/models/ErrorRes.java b/health-services/output/src/main/java/digit/web/models/ErrorRes.java new file mode 100644 index 00000000000..00ac425e528 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/ErrorRes.java @@ -0,0 +1,46 @@ +package digit.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.ArrayList; +import java.util.List; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * All APIs will return ErrorRes in case of failure which will carry ResponseInfo as metadata and Error object as actual representation of error. In case of bulk apis, some apis may chose to return the array of Error objects to indicate individual failure. + */ +@Schema(description = "All APIs will return ErrorRes in case of failure which will carry ResponseInfo as metadata and Error object as actual representation of error. In case of bulk apis, some apis may chose to return the array of Error objects to indicate individual failure.") +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ErrorRes { + @JsonProperty("ResponseInfo") + @NotNull + + @Valid + private ResponseInfo responseInfo = null; + + @JsonProperty("Errors") + @Valid + private List errors = null; + + + public ErrorRes addErrorsItem(Error errorsItem) { + if (this.errors == null) { + this.errors = new ArrayList<>(); + } + this.errors.add(errorsItem); + return this; + } + +} diff --git a/health-services/output/src/main/java/digit/web/models/File.java b/health-services/output/src/main/java/digit/web/models/File.java new file mode 100644 index 00000000000..af73c7036e8 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/File.java @@ -0,0 +1,74 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.UUID; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * File + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class File { + @JsonProperty("id") + + @Valid + private UUID id = null; + + @JsonProperty("filestoreId") + @NotNull + + @Size(min=1,max=32) private String filestoreId = null; + + /** + * The original file type of the Input + */ + public enum InputFileTypeEnum { + EXCEL("Excel"), + + SHAPEFILE("Shapefile"), + + GEOJSON("GeoJSON"); + + private String value; + + InputFileTypeEnum(String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static InputFileTypeEnum fromValue(String text) { + for (InputFileTypeEnum b : InputFileTypeEnum.values()) { + if (String.valueOf(b.value).equals(text)) { + return b; + } + } + return null; + } + } @JsonProperty("inputFileType") + @NotNull + + private InputFileTypeEnum inputFileType = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/Operation.java b/health-services/output/src/main/java/digit/web/models/Operation.java new file mode 100644 index 00000000000..c77e9f8015b --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/Operation.java @@ -0,0 +1,88 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.UUID; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * Operation + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Operation { + @JsonProperty("id") + + @Valid + private UUID id = null; + + @JsonProperty("input") + @NotNull + + @Size(min=1,max=32) private String input = null; + + /** + * The operator used in the operation + */ + public enum OperatorEnum { + PLUS("+"), + + MINUS("-"), + + SLASH("/"), + + STAR("*"), + + PERCENT("%"), + + _U("**"); + + private String value; + + OperatorEnum(String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static OperatorEnum fromValue(String text) { + for (OperatorEnum b : OperatorEnum.values()) { + if (String.valueOf(b.value).equals(text)) { + return b; + } + } + return null; + } + } @JsonProperty("operator") + @NotNull + + private OperatorEnum operator = null; + + @JsonProperty("assumptionValue") + + private String assumptionValue = null; + + @JsonProperty("output") + + @Size(min=1,max=32) private String output = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/Plan.java b/health-services/output/src/main/java/digit/web/models/Plan.java new file mode 100644 index 00000000000..f5594178dec --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/Plan.java @@ -0,0 +1,93 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import digit.web.models.Activity; +import digit.web.models.Target; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import org.springframework.core.io.Resource; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * Plan + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Plan { + @JsonProperty("id") + + @Valid + private UUID id = null; + + @JsonProperty("tenantId") + + private String tenantId = null; + + @JsonProperty("locality") + + @Size(min=2) private String locality = null; + + @JsonProperty("executionPlanId") + + private String executionPlanId = null; + + @JsonProperty("planConfigurationId") + + private String planConfigurationId = null; + + @JsonProperty("additionalDetails") + + private Object additionalDetails = null; + + @JsonProperty("activities") + @Valid + private List activities = null; + + @JsonProperty("resources") + @Valid + private List resources = null; + + @JsonProperty("targets") + @Valid + private List targets = null; + + + public Plan addActivitiesItem(Activity activitiesItem) { + if (this.activities == null) { + this.activities = new ArrayList<>(); + } + this.activities.add(activitiesItem); + return this; + } + + public Plan addResourcesItem(Resource resourcesItem) { + if (this.resources == null) { + this.resources = new ArrayList<>(); + } + this.resources.add(resourcesItem); + return this; + } + + public Plan addTargetsItem(Target targetsItem) { + if (this.targets == null) { + this.targets = new ArrayList<>(); + } + this.targets.add(targetsItem); + return this; + } + +} diff --git a/health-services/output/src/main/java/digit/web/models/PlanConfiguration.java b/health-services/output/src/main/java/digit/web/models/PlanConfiguration.java new file mode 100644 index 00000000000..e3822ca1782 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/PlanConfiguration.java @@ -0,0 +1,92 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import digit.web.models.Assumption; +import digit.web.models.Operation; +import digit.web.models.ResourceMapping; +import io.swagger.v3.oas.annotations.media.Schema; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * PlanConfiguration + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanConfiguration { + @JsonProperty("id") + + @Valid + private UUID id = null; + + @JsonProperty("tenantId") + @NotNull + + private String tenantId = null; + + @JsonProperty("name") + @NotNull + + @Size(min=2) private String name = null; + + @JsonProperty("executionPlanId") + + private String executionPlanId = null; + + @JsonProperty("files") + @NotNull + @Valid + private List files = new ArrayList<>(); + + @JsonProperty("assumptions") + @NotNull + @Valid + private List assumptions = new ArrayList<>(); + + @JsonProperty("operations") + @NotNull + @Valid + private List operations = new ArrayList<>(); + + @JsonProperty("resourceMapping") + @NotNull + @Valid + private List resourceMapping = new ArrayList<>(); + + + public PlanConfiguration addFilesItem(File filesItem) { + this.files.add(filesItem); + return this; + } + + public PlanConfiguration addAssumptionsItem(Assumption assumptionsItem) { + this.assumptions.add(assumptionsItem); + return this; + } + + public PlanConfiguration addOperationsItem(Operation operationsItem) { + this.operations.add(operationsItem); + return this; + } + + public PlanConfiguration addResourceMappingItem(ResourceMapping resourceMappingItem) { + this.resourceMapping.add(resourceMappingItem); + return this; + } + +} diff --git a/health-services/output/src/main/java/digit/web/models/PlanConfigurationRequest.java b/health-services/output/src/main/java/digit/web/models/PlanConfigurationRequest.java new file mode 100644 index 00000000000..c1b14afc589 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/PlanConfigurationRequest.java @@ -0,0 +1,34 @@ +package digit.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * PlanConfigurationRequest + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanConfigurationRequest { + @JsonProperty("RequestInfo") + + @Valid + private RequestInfo requestInfo = null; + + @JsonProperty("PlanConfiguration") + + @Valid + private PlanConfiguration planConfiguration = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/PlanConfigurationResponse.java b/health-services/output/src/main/java/digit/web/models/PlanConfigurationResponse.java new file mode 100644 index 00000000000..2559cd16187 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/PlanConfigurationResponse.java @@ -0,0 +1,42 @@ +package digit.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.ArrayList; +import java.util.List; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * PlanConfigurationResponse + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanConfigurationResponse { + @JsonProperty("ResponseInfo") + + @Valid + private ResponseInfo responseInfo = null; + + @JsonProperty("PlanConfigurationResponse") + @Valid + private List planConfigurationResponse = null; + + + public PlanConfigurationResponse addPlanConfigurationResponseItem(PlanConfiguration planConfigurationResponseItem) { + if (this.planConfigurationResponse == null) { + this.planConfigurationResponse = new ArrayList<>(); + } + this.planConfigurationResponse.add(planConfigurationResponseItem); + return this; + } + +} diff --git a/health-services/output/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java b/health-services/output/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java new file mode 100644 index 00000000000..4ab40c234a2 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java @@ -0,0 +1,38 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.v3.oas.annotations.media.Schema; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * PlanConfigurationSearchCriteria + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanConfigurationSearchCriteria { + @JsonProperty("tenantId") + + @Size(min=1,max=100) private String tenantId = null; + + @JsonProperty("name") + + private String name = null; + + @JsonProperty("executionPlan") + + private String executionPlan = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java b/health-services/output/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java new file mode 100644 index 00000000000..b46d9cdb675 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java @@ -0,0 +1,33 @@ +package digit.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * PlanConfigurationSearchRequest + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanConfigurationSearchRequest { + @JsonProperty("RequestInfo") + + @Valid + private RequestInfo requestInfo = null; + + @JsonProperty("PlanConfigurationSearchCriteria") + + @Valid + private PlanConfigurationSearchCriteria planConfigurationSearchCriteria = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/PlanCreateRequest.java b/health-services/output/src/main/java/digit/web/models/PlanCreateRequest.java new file mode 100644 index 00000000000..14d8559fdce --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/PlanCreateRequest.java @@ -0,0 +1,33 @@ +package digit.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * PlanCreateRequest + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanCreateRequest { + @JsonProperty("RequestInfo") + + @Valid + private RequestInfo requestInfo = null; + + @JsonProperty("Plan") + + @Valid + private Plan plan = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/PlanEditRequest.java b/health-services/output/src/main/java/digit/web/models/PlanEditRequest.java new file mode 100644 index 00000000000..91492c58575 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/PlanEditRequest.java @@ -0,0 +1,33 @@ +package digit.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * PlanEditRequest + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanEditRequest { + @JsonProperty("RequestInfo") + + @Valid + private RequestInfo requestInfo = null; + + @JsonProperty("Plan") + + @Valid + private Plan plan = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/PlanSearchCriteria.java b/health-services/output/src/main/java/digit/web/models/PlanSearchCriteria.java new file mode 100644 index 00000000000..d520e9f899c --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/PlanSearchCriteria.java @@ -0,0 +1,38 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.v3.oas.annotations.media.Schema; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * PlanSearchCriteria + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanSearchCriteria { + @JsonProperty("tenantId") + + @Size(min=1,max=100) private String tenantId = null; + + @JsonProperty("locality") + + private String locality = null; + + @JsonProperty("executionPlanId") + + private String executionPlanId = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/PlanSearchRequest.java b/health-services/output/src/main/java/digit/web/models/PlanSearchRequest.java new file mode 100644 index 00000000000..f911e1c1e7b --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/PlanSearchRequest.java @@ -0,0 +1,33 @@ +package digit.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * PlanSearchRequest + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanSearchRequest { + @JsonProperty("RequestInfo") + + @Valid + private RequestInfo requestInfo = null; + + @JsonProperty("PlanSearchCriteria") + + @Valid + private PlanSearchCriteria planSearchCriteria = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/PlanSearchResponse.java b/health-services/output/src/main/java/digit/web/models/PlanSearchResponse.java new file mode 100644 index 00000000000..0e9a5e17d4e --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/PlanSearchResponse.java @@ -0,0 +1,42 @@ +package digit.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.ArrayList; +import java.util.List; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * PlanSearchResponse + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanSearchResponse { + @JsonProperty("ResponseInfo") + + @Valid + private ResponseInfo responseInfo = null; + + @JsonProperty("Plan") + @Valid + private List plan = null; + + + public PlanSearchResponse addPlanItem(Plan planItem) { + if (this.plan == null) { + this.plan = new ArrayList<>(); + } + this.plan.add(planItem); + return this; + } + +} diff --git a/health-services/output/src/main/java/digit/web/models/Resource.java b/health-services/output/src/main/java/digit/web/models/Resource.java new file mode 100644 index 00000000000..60f920327fc --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/Resource.java @@ -0,0 +1,42 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.v3.oas.annotations.media.Schema; +import java.math.BigDecimal; +import java.util.UUID; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * Resource + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Resource { + @JsonProperty("id") + + @Valid + private UUID id = null; + + @JsonProperty("resourceType") + + private String resourceType = null; + + @JsonProperty("estimatedNumber") + + @Valid + private BigDecimal estimatedNumber = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/ResourceMapping.java b/health-services/output/src/main/java/digit/web/models/ResourceMapping.java new file mode 100644 index 00000000000..7fa024f7ad6 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/ResourceMapping.java @@ -0,0 +1,34 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.v3.oas.annotations.media.Schema; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * ResourceMapping + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ResourceMapping { + @JsonProperty("mappedFrom") + + private String mappedFrom = null; + + @JsonProperty("mappedTo") + + private String mappedTo = null; + + +} diff --git a/health-services/output/src/main/java/digit/web/models/Target.java b/health-services/output/src/main/java/digit/web/models/Target.java new file mode 100644 index 00000000000..2c5d1333b62 --- /dev/null +++ b/health-services/output/src/main/java/digit/web/models/Target.java @@ -0,0 +1,45 @@ +package digit.web.models; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.UUID; +import org.springframework.validation.annotation.Validated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.Data; +import lombok.Builder; + +/** + * Target + */ +@Validated +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Target { + @JsonProperty("id") + + @Valid + private UUID id = null; + + @JsonProperty("taskId") + + @Valid + private UUID taskId = null; + + @JsonProperty("metric") + + private String metric = null; + + @JsonProperty("metricDetail") + + private Object metricDetail = null; + + +} diff --git a/health-services/output/src/main/resources/application.properties b/health-services/output/src/main/resources/application.properties new file mode 100644 index 00000000000..3aeb15f40fd --- /dev/null +++ b/health-services/output/src/main/resources/application.properties @@ -0,0 +1,83 @@ +server.contextPath=/plan-service +server.port=8080 +app.timezone=UTC + +#DATABASE CONFIGURATION +spring.datasource.driver-class-name=org.postgresql.Driver +spring.datasource.url=jdbc:postgresql://localhost:5432/postgres +spring.datasource.username=postgres +spring.datasource.password=postgres + +#FLYWAY CONFIGURATION +spring.flyway.url=jdbc:postgresql://localhost:5432/postgres +spring.flyway.user=postgres +spring.flyway.password=postgres +spring.flyway.table=public +spring.flyway.baseline-on-migrate=true +spring.flyway.outOfOrder=true +spring.flyway.locations=classpath:/db/migration/main +spring.flyway.enabled=true + +# KAFKA SERVER CONFIGURATIONS +kafka.config.bootstrap_server_config=localhost:9092 +spring.kafka.consumer.value-deserializer=org.egov.tracer.kafka.deserializer.HashMapDeserializer +spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer +spring.kafka.consumer.group-id=plan-service +spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer +spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer +spring.kafka.listener.missing-topics-fatal=false +spring.kafka.consumer.properties.spring.json.use.type.headers=false + +# KAFKA CONSUMER CONFIGURATIONS +kafka.consumer.config.auto_commit=true +kafka.consumer.config.auto_commit_interval=100 +kafka.consumer.config.session_timeout=15000 +kafka.consumer.config.auto_offset_reset=earliest +# KAFKA PRODUCER CONFIGURATIONS +kafka.producer.config.retries_config=0 +kafka.producer.config.batch_size_config=16384 +kafka.producer.config.linger_ms_config=1 +kafka.producer.config.buffer_memory_config=33554432 + +#Localization config +egov.localization.host=https://dev.digit.org +egov.localization.workDir.path=/localization/messages/v1 +egov.localization.context.path=/localization/messages/v1 +egov.localization.search.endpoint=/_search +egov.localization.statelevel=true + +#mdms urls +egov.mdms.host=https://dev.digit.org +egov.mdms.search.endpoint=/egov-mdms-service/v1/_search + +#hrms urls +egov.hrms.host=https://dev.digit.org +egov.hrms.search.endpoint=/egov-hrms/employees/_search + +#User config +egov.user.host=https://dev.digit.org +egov.user.context.path=/user/users +egov.user.create.path=/_createnovalidate +egov.user.search.path=/user/_search +egov.user.update.path=/_updatenovalidate + +#Idgen Config +egov.idgen.host=https://dev.digit.org/ +egov.idgen.path=egov-idgen/id/_generate + +#Workflow config +is.workflow.enabled=true +egov.workflow.host=https://dev.digit.org +egov.workflow.transition.path=/egov-workflow-v2/egov-wf/process/_transition +egov.workflow.businessservice.search.path=/egov-workflow-v2/egov-wf/businessservice/_search +egov.workflow.processinstance.search.path=/egov-workflow-v2/egov-wf/process/_search + +#url shortner +egov.url.shortner.host=https://dev.digit.org +egov.url.shortner.endpoint=/egov-url-shortening/shortener + +egov.sms.notification.topic=egov.core.notification.sms +kafka.topics.receipt.create=dss-collection + +# The value of the following field should be changed to service specific name +kafka.topics.consumer=service-consumer-topic \ No newline at end of file diff --git a/health-services/output/src/main/resources/db/Dockerfile b/health-services/output/src/main/resources/db/Dockerfile new file mode 100644 index 00000000000..60fc07ce69f --- /dev/null +++ b/health-services/output/src/main/resources/db/Dockerfile @@ -0,0 +1,9 @@ +FROM egovio/flyway:4.1.2 + +COPY ./migration/main /flyway/sql + +COPY migrate.sh /usr/bin/migrate.sh + +RUN chmod +x /usr/bin/migrate.sh + +CMD ["/usr/bin/migrate.sh"] \ No newline at end of file diff --git a/health-services/output/src/main/resources/db/migrate.sh b/health-services/output/src/main/resources/db/migrate.sh new file mode 100644 index 00000000000..43960b25cdb --- /dev/null +++ b/health-services/output/src/main/resources/db/migrate.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +flyway -url=$DB_URL -table=$SCHEMA_TABLE -user=$FLYWAY_USER -password=$FLYWAY_PASSWORD -locations=$FLYWAY_LOCATIONS -baselineOnMigrate=true -outOfOrder=true -ignoreMissingMigrations=true migrate \ No newline at end of file diff --git a/health-services/output/src/test/java/digit/TestConfiguration.java b/health-services/output/src/test/java/digit/TestConfiguration.java new file mode 100644 index 00000000000..570236cfc94 --- /dev/null +++ b/health-services/output/src/test/java/digit/TestConfiguration.java @@ -0,0 +1,16 @@ +package digit; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.core.KafkaTemplate; + +import static org.mockito.Mockito.mock; + +@Configuration +public class TestConfiguration { + @Bean + @SuppressWarnings("unchecked") + public KafkaTemplate kafkaTemplate() { + return mock(KafkaTemplate.class); + } +} \ No newline at end of file diff --git a/health-services/output/src/test/java/digit/web/controllers/ConfigApiControllerTest.java b/health-services/output/src/test/java/digit/web/controllers/ConfigApiControllerTest.java new file mode 100644 index 00000000000..601fe9a0834 --- /dev/null +++ b/health-services/output/src/test/java/digit/web/controllers/ConfigApiControllerTest.java @@ -0,0 +1,72 @@ +package digit.web.controllers; + +import org.junit.Test; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import digit.TestConfiguration; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** +* API tests for ConfigApiController +*/ +@Ignore +@RunWith(SpringRunner.class) +@WebMvcTest(ConfigApiController.class) +@Import(TestConfiguration.class) +public class ConfigApiControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Test + public void configCreatePostSuccess() throws Exception { + mockMvc.perform(post("/plan/config/_create").contentType(MediaType + .APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + } + + @Test + public void configCreatePostFailure() throws Exception { + mockMvc.perform(post("/plan/config/_create").contentType(MediaType + .APPLICATION_JSON_UTF8)) + .andExpect(status().isBadRequest()); + } + + @Test + public void configSearchPostSuccess() throws Exception { + mockMvc.perform(post("/plan/config/_search").contentType(MediaType + .APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + } + + @Test + public void configSearchPostFailure() throws Exception { + mockMvc.perform(post("/plan/config/_search").contentType(MediaType + .APPLICATION_JSON_UTF8)) + .andExpect(status().isBadRequest()); + } + + @Test + public void configUpdatePostSuccess() throws Exception { + mockMvc.perform(post("/plan/config/_update").contentType(MediaType + .APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + } + + @Test + public void configUpdatePostFailure() throws Exception { + mockMvc.perform(post("/plan/config/_update").contentType(MediaType + .APPLICATION_JSON_UTF8)) + .andExpect(status().isBadRequest()); + } + +} diff --git a/health-services/output/src/test/java/digit/web/controllers/CreateApiControllerTest.java b/health-services/output/src/test/java/digit/web/controllers/CreateApiControllerTest.java new file mode 100644 index 00000000000..8f26c9fb211 --- /dev/null +++ b/health-services/output/src/test/java/digit/web/controllers/CreateApiControllerTest.java @@ -0,0 +1,43 @@ +package digit.web.controllers; + +import org.junit.Test; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import digit.TestConfiguration; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** +* API tests for CreateApiController +*/ +@Ignore +@RunWith(SpringRunner.class) +@WebMvcTest(CreateApiController.class) +@Import(TestConfiguration.class) +public class CreateApiControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Test + public void createPostSuccess() throws Exception { + mockMvc.perform(post("/plan/_create").contentType(MediaType + .APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + } + + @Test + public void createPostFailure() throws Exception { + mockMvc.perform(post("/plan/_create").contentType(MediaType + .APPLICATION_JSON_UTF8)) + .andExpect(status().isBadRequest()); + } + +} diff --git a/health-services/output/src/test/java/digit/web/controllers/SearchApiControllerTest.java b/health-services/output/src/test/java/digit/web/controllers/SearchApiControllerTest.java new file mode 100644 index 00000000000..de1aac63955 --- /dev/null +++ b/health-services/output/src/test/java/digit/web/controllers/SearchApiControllerTest.java @@ -0,0 +1,43 @@ +package digit.web.controllers; + +import org.junit.Test; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.context.annotation.Import; +import org.springframework.http.MediaType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import digit.TestConfiguration; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** +* API tests for SearchApiController +*/ +@Ignore +@RunWith(SpringRunner.class) +@WebMvcTest(SearchApiController.class) +@Import(TestConfiguration.class) +public class SearchApiControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Test + public void searchPostSuccess() throws Exception { + mockMvc.perform(post("/plan/_search").contentType(MediaType + .APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + } + + @Test + public void searchPostFailure() throws Exception { + mockMvc.perform(post("/plan/_search").contentType(MediaType + .APPLICATION_JSON_UTF8)) + .andExpect(status().isBadRequest()); + } + +} diff --git a/health-services/output/src/test/java/digit/web/controllers/UpdateApiControllerTest.java b/health-services/output/src/test/java/digit/web/controllers/UpdateApiControllerTest.java new file mode 100644 index 00000000000..c5c5f3d8f29 --- /dev/null +++ b/health-services/output/src/test/java/digit/web/controllers/UpdateApiControllerTest.java @@ -0,0 +1,43 @@ +package digit.web.controllers; + + +import org.junit.Ignore; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.context.annotation.Import; +import org.springframework.http.MediaType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import digit.TestConfiguration; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** +* API tests for UpdateApiController +*/ +@Ignore +@RunWith(SpringRunner.class) +@WebMvcTest(UpdateApiController.class) +@Import(TestConfiguration.class) +public class UpdateApiControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Test + public void updatePostSuccess() throws Exception { + mockMvc.perform(post("/plan/_update").contentType(MediaType + .APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + } + + @Test + public void updatePostFailure() throws Exception { + mockMvc.perform(post("/plan/_update").contentType(MediaType + .APPLICATION_JSON_UTF8)) + .andExpect(status().isBadRequest()); + } + +} From 717337060a1e09656428588ff9561c60d1bf2cbc Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 5 Mar 2024 14:15:02 +0530 Subject: [PATCH 02/53] HLM-5117 renaming output folder to plan-service --- build/build-config.yml | 7 ++ .../web/controllers/ConfigApiController.java | 87 ------------------- .../web/controllers/CreateApiController.java | 62 ------------- .../web/controllers/SearchApiController.java | 62 ------------- .../web/controllers/UpdateApiController.java | 62 ------------- .../{output => plan-service}/README.md | 0 .../{output => plan-service}/pom.xml | 0 .../src/main/java/digit/Main.java | 0 .../main/java/digit/config/Configuration.java | 0 .../java/digit/config/MainConfiguration.java | 0 .../java/digit/config/ServiceConstants.java | 0 .../src/main/java/digit/kafka/Consumer.java | 0 .../src/main/java/digit/kafka/Producer.java | 0 .../repository/ServiceRequestRepository.java | 0 .../java/digit/service/EnrichmentService.java | 0 .../service/PlanConfigurationService.java | 0 .../src/main/java/digit/util/IdgenUtil.java | 0 .../src/main/java/digit/util/MdmsUtil.java | 0 .../java/digit/util/ResponseInfoFactory.java | 0 .../java/digit/util/UrlShortenerUtil.java | 0 .../src/main/java/digit/util/UserUtil.java | 0 .../main/java/digit/util/WorkflowUtil.java | 0 .../web/controllers/ConfigApiController.java | 60 +++++++++++++ .../web/controllers/CreateApiController.java | 50 +++++++++++ .../web/controllers/SearchApiController.java | 51 +++++++++++ .../web/controllers/UpdateApiController.java | 49 +++++++++++ .../main/java/digit/web/models/Activity.java | 0 .../java/digit/web/models/Assumption.java | 0 .../main/java/digit/web/models/Condition.java | 0 .../src/main/java/digit/web/models/Error.java | 0 .../main/java/digit/web/models/ErrorRes.java | 0 .../src/main/java/digit/web/models/File.java | 0 .../main/java/digit/web/models/Operation.java | 0 .../src/main/java/digit/web/models/Plan.java | 0 .../digit/web/models/PlanConfiguration.java | 0 .../web/models/PlanConfigurationRequest.java | 0 .../web/models/PlanConfigurationResponse.java | 0 .../PlanConfigurationSearchCriteria.java | 0 .../PlanConfigurationSearchRequest.java | 0 .../digit/web/models/PlanCreateRequest.java | 0 .../digit/web/models/PlanEditRequest.java | 0 .../digit/web/models/PlanSearchCriteria.java | 0 .../digit/web/models/PlanSearchRequest.java | 0 .../digit/web/models/PlanSearchResponse.java | 0 .../main/java/digit/web/models/Resource.java | 0 .../digit/web/models/ResourceMapping.java | 0 .../main/java/digit/web/models/Target.java | 0 .../src/main/resources/application.properties | 4 +- .../src/main/resources/db/Dockerfile | 0 .../src/main/resources/db/migrate.sh | 0 ...5113045__plan_configuration_create_ddl.sql | 73 ++++++++++++++++ .../test/java/digit/TestConfiguration.java | 0 .../controllers/ConfigApiControllerTest.java | 0 .../controllers/CreateApiControllerTest.java | 0 .../controllers/SearchApiControllerTest.java | 0 .../controllers/UpdateApiControllerTest.java | 0 56 files changed, 292 insertions(+), 275 deletions(-) delete mode 100644 health-services/output/src/main/java/digit/web/controllers/ConfigApiController.java delete mode 100644 health-services/output/src/main/java/digit/web/controllers/CreateApiController.java delete mode 100644 health-services/output/src/main/java/digit/web/controllers/SearchApiController.java delete mode 100644 health-services/output/src/main/java/digit/web/controllers/UpdateApiController.java rename health-services/{output => plan-service}/README.md (100%) rename health-services/{output => plan-service}/pom.xml (100%) rename health-services/{output => plan-service}/src/main/java/digit/Main.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/config/Configuration.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/config/MainConfiguration.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/config/ServiceConstants.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/kafka/Consumer.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/kafka/Producer.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/repository/ServiceRequestRepository.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/service/EnrichmentService.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/service/PlanConfigurationService.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/util/IdgenUtil.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/util/MdmsUtil.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/util/ResponseInfoFactory.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/util/UrlShortenerUtil.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/util/UserUtil.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/util/WorkflowUtil.java (100%) create mode 100644 health-services/plan-service/src/main/java/digit/web/controllers/ConfigApiController.java create mode 100644 health-services/plan-service/src/main/java/digit/web/controllers/CreateApiController.java create mode 100644 health-services/plan-service/src/main/java/digit/web/controllers/SearchApiController.java create mode 100644 health-services/plan-service/src/main/java/digit/web/controllers/UpdateApiController.java rename health-services/{output => plan-service}/src/main/java/digit/web/models/Activity.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/Assumption.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/Condition.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/Error.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/ErrorRes.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/File.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/Operation.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/Plan.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/PlanConfiguration.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/PlanConfigurationRequest.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/PlanConfigurationResponse.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/PlanCreateRequest.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/PlanEditRequest.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/PlanSearchCriteria.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/PlanSearchRequest.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/PlanSearchResponse.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/Resource.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/ResourceMapping.java (100%) rename health-services/{output => plan-service}/src/main/java/digit/web/models/Target.java (100%) rename health-services/{output => plan-service}/src/main/resources/application.properties (95%) rename health-services/{output => plan-service}/src/main/resources/db/Dockerfile (100%) rename health-services/{output => plan-service}/src/main/resources/db/migrate.sh (100%) create mode 100644 health-services/plan-service/src/main/resources/db/migration/main/V20240305113045__plan_configuration_create_ddl.sql rename health-services/{output => plan-service}/src/test/java/digit/TestConfiguration.java (100%) rename health-services/{output => plan-service}/src/test/java/digit/web/controllers/ConfigApiControllerTest.java (100%) rename health-services/{output => plan-service}/src/test/java/digit/web/controllers/CreateApiControllerTest.java (100%) rename health-services/{output => plan-service}/src/test/java/digit/web/controllers/SearchApiControllerTest.java (100%) rename health-services/{output => plan-service}/src/test/java/digit/web/controllers/UpdateApiControllerTest.java (100%) diff --git a/build/build-config.yml b/build/build-config.yml index 13bc1db43fa..10f839d51e8 100644 --- a/build/build-config.yml +++ b/build/build-config.yml @@ -168,3 +168,10 @@ config: dockerfile: "build/maven/Dockerfile" - work-dir: "core-services/egov-hrms/src/main/resources/db" image-name: "health-hrms-db" + - name: "builds/health-campaign-services/health-services/facility" + build: + - work-dir: "health-services/facility" + image-name: "facility" + dockerfile: "build/maven/Dockerfile" + - work-dir: "health-services/facility/src/main/resources/db" + image-name: "facility-db" diff --git a/health-services/output/src/main/java/digit/web/controllers/ConfigApiController.java b/health-services/output/src/main/java/digit/web/controllers/ConfigApiController.java deleted file mode 100644 index 69b1edb71c0..00000000000 --- a/health-services/output/src/main/java/digit/web/controllers/ConfigApiController.java +++ /dev/null @@ -1,87 +0,0 @@ -package digit.web.controllers; - - -import digit.service.PlanConfigurationService; -import digit.web.models.PlanConfigurationRequest; -import digit.web.models.PlanConfigurationResponse; -import digit.web.models.PlanConfigurationSearchRequest; -import javax.validation.Valid; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.servlet.http.HttpServletRequest; -import org.egov.common.contract.response.ResponseInfo; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestMapping; -import java.io.IOException; -import java.util.*; - -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") -@Controller -@RequestMapping("/plan") -public class ConfigApiController { - - private final ObjectMapper objectMapper; - - private final HttpServletRequest request; - - private final PlanConfigurationService planConfigurationService; - - @Autowired - public ConfigApiController(ObjectMapper objectMapper, HttpServletRequest request, PlanConfigurationService planConfigurationService) { - this.objectMapper = objectMapper; - this.request = request; - this.planConfigurationService = planConfigurationService; - } - - @RequestMapping(value = "/config/_create", method = RequestMethod.POST) - public ResponseEntity configCreatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationRequest body) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - PlanConfigurationRequest planConfigurationRequest = planConfigurationService.create(body); - PlanConfigurationResponse response = PlanConfigurationResponse.builder() - .planConfigurationResponse(Collections.singletonList(planConfigurationRequest.getPlanConfiguration())) - .responseInfo(new ResponseInfo()) - .build(); - - return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); - - } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); - } - - @RequestMapping(value = "/config/_search", method = RequestMethod.POST) - public ResponseEntity configSearchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationSearchRequest body) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"ResponseInfo\" : { \"ver\" : \"ver\", \"resMsgId\" : \"resMsgId\", \"msgId\" : \"msgId\", \"apiId\" : \"apiId\", \"ts\" : 0, \"status\" : \"SUCCESSFUL\" }, \"PlanConfigurationResponse\" : [ { \"executionPlanId\" : \"executionPlanId\", \"operations\" : [ { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" }, { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" } ], \"resourceMapping\" : [ { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" }, { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" } ], \"tenantId\" : \"tenantId\", \"name\" : \"name\", \"files\" : [ { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"assumptions\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" } ] }, { \"executionPlanId\" : \"executionPlanId\", \"operations\" : [ { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" }, { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" } ], \"resourceMapping\" : [ { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" }, { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" } ], \"tenantId\" : \"tenantId\", \"name\" : \"name\", \"files\" : [ { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"assumptions\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" } ] } ]}", PlanConfigurationResponse.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); - } - - @RequestMapping(value = "/config/_update", method = RequestMethod.POST) - public ResponseEntity configUpdatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationRequest body) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"ResponseInfo\" : { \"ver\" : \"ver\", \"resMsgId\" : \"resMsgId\", \"msgId\" : \"msgId\", \"apiId\" : \"apiId\", \"ts\" : 0, \"status\" : \"SUCCESSFUL\" }, \"PlanConfigurationResponse\" : [ { \"executionPlanId\" : \"executionPlanId\", \"operations\" : [ { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" }, { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" } ], \"resourceMapping\" : [ { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" }, { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" } ], \"tenantId\" : \"tenantId\", \"name\" : \"name\", \"files\" : [ { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"assumptions\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" } ] }, { \"executionPlanId\" : \"executionPlanId\", \"operations\" : [ { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" }, { \"output\" : \"output\", \"input\" : \"input\", \"assumptionValue\" : \"assumptionValue\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"operator\" : \"+\" } ], \"resourceMapping\" : [ { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" }, { \"mappedFrom\" : \"mappedFrom\", \"mappedTo\" : \"mappedTo\" } ], \"tenantId\" : \"tenantId\", \"name\" : \"name\", \"files\" : [ { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"filestoreId\" : \"filestoreId\", \"inputFileType\" : \"Excel\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"assumptions\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"value\" : 6.027456183070403, \"key\" : \"key\" } ] } ]}", PlanConfigurationResponse.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); - } -} diff --git a/health-services/output/src/main/java/digit/web/controllers/CreateApiController.java b/health-services/output/src/main/java/digit/web/controllers/CreateApiController.java deleted file mode 100644 index 1e1ee102d8a..00000000000 --- a/health-services/output/src/main/java/digit/web/controllers/CreateApiController.java +++ /dev/null @@ -1,62 +0,0 @@ -package digit.web.controllers; - - -import digit.web.models.ErrorRes; -import digit.web.models.PlanCreateRequest; -import digit.web.models.PlanSearchResponse; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.media.Schema; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.bind.annotation.RequestMapping; -import java.io.IOException; -import java.util.*; - -import javax.validation.constraints.*; -import javax.validation.Valid; -import javax.servlet.http.HttpServletRequest; -import java.util.Optional; - -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") -@Controller -@RequestMapping("/plan") -public class CreateApiController { - - private final ObjectMapper objectMapper; - - private final HttpServletRequest request; - - @Autowired - public CreateApiController(ObjectMapper objectMapper, HttpServletRequest request) { - this.objectMapper = objectMapper; - this.request = request; - } - - @RequestMapping(value = "/_create", method = RequestMethod.POST) - public ResponseEntity createPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanCreateRequest body) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"ResponseInfo\" : { \"ver\" : \"ver\", \"resMsgId\" : \"resMsgId\", \"msgId\" : \"msgId\", \"apiId\" : \"apiId\", \"ts\" : 0, \"status\" : \"SUCCESSFUL\" }, \"Plan\" : [ { \"executionPlanId\" : \"executionPlanId\", \"planConfigurationId\" : \"planConfigurationId\", \"activities\" : [ { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] }, { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] } ], \"tenantId\" : \"tenantId\", \"locality\" : \"locality\", \"resources\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"additionalDetails\" : { }, \"targets\" : [ { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ] }, { \"executionPlanId\" : \"executionPlanId\", \"planConfigurationId\" : \"planConfigurationId\", \"activities\" : [ { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] }, { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] } ], \"tenantId\" : \"tenantId\", \"locality\" : \"locality\", \"resources\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"additionalDetails\" : { }, \"targets\" : [ { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ] } ]}", PlanSearchResponse.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); - } - -} diff --git a/health-services/output/src/main/java/digit/web/controllers/SearchApiController.java b/health-services/output/src/main/java/digit/web/controllers/SearchApiController.java deleted file mode 100644 index 271632ccaf4..00000000000 --- a/health-services/output/src/main/java/digit/web/controllers/SearchApiController.java +++ /dev/null @@ -1,62 +0,0 @@ -package digit.web.controllers; - - -import digit.web.models.ErrorRes; -import digit.web.models.PlanSearchRequest; -import digit.web.models.PlanSearchResponse; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.media.Schema; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.bind.annotation.RequestMapping; -import java.io.IOException; -import java.util.*; - -import javax.validation.constraints.*; -import javax.validation.Valid; -import javax.servlet.http.HttpServletRequest; -import java.util.Optional; - -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") -@Controller -@RequestMapping("/plan") -public class SearchApiController { - - private final ObjectMapper objectMapper; - - private final HttpServletRequest request; - - @Autowired - public SearchApiController(ObjectMapper objectMapper, HttpServletRequest request) { - this.objectMapper = objectMapper; - this.request = request; - } - - @RequestMapping(value = "/_search", method = RequestMethod.POST) - public ResponseEntity searchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanSearchRequest body) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"ResponseInfo\" : { \"ver\" : \"ver\", \"resMsgId\" : \"resMsgId\", \"msgId\" : \"msgId\", \"apiId\" : \"apiId\", \"ts\" : 0, \"status\" : \"SUCCESSFUL\" }, \"Plan\" : [ { \"executionPlanId\" : \"executionPlanId\", \"planConfigurationId\" : \"planConfigurationId\", \"activities\" : [ { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] }, { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] } ], \"tenantId\" : \"tenantId\", \"locality\" : \"locality\", \"resources\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"additionalDetails\" : { }, \"targets\" : [ { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ] }, { \"executionPlanId\" : \"executionPlanId\", \"planConfigurationId\" : \"planConfigurationId\", \"activities\" : [ { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] }, { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] } ], \"tenantId\" : \"tenantId\", \"locality\" : \"locality\", \"resources\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"additionalDetails\" : { }, \"targets\" : [ { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ] } ]}", PlanSearchResponse.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); - } - -} diff --git a/health-services/output/src/main/java/digit/web/controllers/UpdateApiController.java b/health-services/output/src/main/java/digit/web/controllers/UpdateApiController.java deleted file mode 100644 index b8ba48f5d3a..00000000000 --- a/health-services/output/src/main/java/digit/web/controllers/UpdateApiController.java +++ /dev/null @@ -1,62 +0,0 @@ -package digit.web.controllers; - - -import digit.web.models.ErrorRes; -import digit.web.models.PlanEditRequest; -import digit.web.models.PlanSearchResponse; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.media.Schema; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.bind.annotation.RequestMapping; -import java.io.IOException; -import java.util.*; - -import javax.validation.constraints.*; -import javax.validation.Valid; -import javax.servlet.http.HttpServletRequest; -import java.util.Optional; - -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") -@Controller -@RequestMapping("/plan") -public class UpdateApiController { - - private final ObjectMapper objectMapper; - - private final HttpServletRequest request; - - @Autowired - public UpdateApiController(ObjectMapper objectMapper, HttpServletRequest request) { - this.objectMapper = objectMapper; - this.request = request; - } - - @RequestMapping(value = "/_update", method = RequestMethod.POST) - public ResponseEntity updatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanEditRequest body) { - String accept = request.getHeader("Accept"); - if (accept != null && accept.contains("application/json")) { - try { - return new ResponseEntity(objectMapper.readValue("{ \"ResponseInfo\" : { \"ver\" : \"ver\", \"resMsgId\" : \"resMsgId\", \"msgId\" : \"msgId\", \"apiId\" : \"apiId\", \"ts\" : 0, \"status\" : \"SUCCESSFUL\" }, \"Plan\" : [ { \"executionPlanId\" : \"executionPlanId\", \"planConfigurationId\" : \"planConfigurationId\", \"activities\" : [ { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] }, { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] } ], \"tenantId\" : \"tenantId\", \"locality\" : \"locality\", \"resources\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"additionalDetails\" : { }, \"targets\" : [ { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ] }, { \"executionPlanId\" : \"executionPlanId\", \"planConfigurationId\" : \"planConfigurationId\", \"activities\" : [ { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] }, { \"resourceId\" : \"resourceId\", \"plannedStartDate\" : 0, \"tenantId\" : \"tenantId\", \"description\" : \"description\", \"id\" : \"id\", \"conditions\" : [ { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" }, { \"expression\" : \"3 <= age <= 11\", \"entityProperty\" : \"age\", \"entity\" : \"PERSON\" } ], \"plannedEndDate\" : 6, \"dependencies\" : [ \"dependencies\", \"dependencies\" ] } ], \"tenantId\" : \"tenantId\", \"locality\" : \"locality\", \"resources\" : [ { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" }, { \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"estimatedNumber\" : 1.4658129805029452, \"resourceType\" : \"STAFF\" } ], \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"additionalDetails\" : { }, \"targets\" : [ { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" }, { \"metricDetail\" : { \"comparator\" : \">\", \"unit\" : \"PERCENT\", \"value\" : 90 }, \"metric\" : \"VACCINATION_COVERAGE\", \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\", \"taskId\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\" } ] } ]}", PlanSearchResponse.class), HttpStatus.NOT_IMPLEMENTED); - } catch (IOException e) { - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - return new ResponseEntity(HttpStatus.NOT_IMPLEMENTED); - } - -} diff --git a/health-services/output/README.md b/health-services/plan-service/README.md similarity index 100% rename from health-services/output/README.md rename to health-services/plan-service/README.md diff --git a/health-services/output/pom.xml b/health-services/plan-service/pom.xml similarity index 100% rename from health-services/output/pom.xml rename to health-services/plan-service/pom.xml diff --git a/health-services/output/src/main/java/digit/Main.java b/health-services/plan-service/src/main/java/digit/Main.java similarity index 100% rename from health-services/output/src/main/java/digit/Main.java rename to health-services/plan-service/src/main/java/digit/Main.java diff --git a/health-services/output/src/main/java/digit/config/Configuration.java b/health-services/plan-service/src/main/java/digit/config/Configuration.java similarity index 100% rename from health-services/output/src/main/java/digit/config/Configuration.java rename to health-services/plan-service/src/main/java/digit/config/Configuration.java diff --git a/health-services/output/src/main/java/digit/config/MainConfiguration.java b/health-services/plan-service/src/main/java/digit/config/MainConfiguration.java similarity index 100% rename from health-services/output/src/main/java/digit/config/MainConfiguration.java rename to health-services/plan-service/src/main/java/digit/config/MainConfiguration.java diff --git a/health-services/output/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java similarity index 100% rename from health-services/output/src/main/java/digit/config/ServiceConstants.java rename to health-services/plan-service/src/main/java/digit/config/ServiceConstants.java diff --git a/health-services/output/src/main/java/digit/kafka/Consumer.java b/health-services/plan-service/src/main/java/digit/kafka/Consumer.java similarity index 100% rename from health-services/output/src/main/java/digit/kafka/Consumer.java rename to health-services/plan-service/src/main/java/digit/kafka/Consumer.java diff --git a/health-services/output/src/main/java/digit/kafka/Producer.java b/health-services/plan-service/src/main/java/digit/kafka/Producer.java similarity index 100% rename from health-services/output/src/main/java/digit/kafka/Producer.java rename to health-services/plan-service/src/main/java/digit/kafka/Producer.java diff --git a/health-services/output/src/main/java/digit/repository/ServiceRequestRepository.java b/health-services/plan-service/src/main/java/digit/repository/ServiceRequestRepository.java similarity index 100% rename from health-services/output/src/main/java/digit/repository/ServiceRequestRepository.java rename to health-services/plan-service/src/main/java/digit/repository/ServiceRequestRepository.java diff --git a/health-services/output/src/main/java/digit/service/EnrichmentService.java b/health-services/plan-service/src/main/java/digit/service/EnrichmentService.java similarity index 100% rename from health-services/output/src/main/java/digit/service/EnrichmentService.java rename to health-services/plan-service/src/main/java/digit/service/EnrichmentService.java diff --git a/health-services/output/src/main/java/digit/service/PlanConfigurationService.java b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java similarity index 100% rename from health-services/output/src/main/java/digit/service/PlanConfigurationService.java rename to health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java diff --git a/health-services/output/src/main/java/digit/util/IdgenUtil.java b/health-services/plan-service/src/main/java/digit/util/IdgenUtil.java similarity index 100% rename from health-services/output/src/main/java/digit/util/IdgenUtil.java rename to health-services/plan-service/src/main/java/digit/util/IdgenUtil.java diff --git a/health-services/output/src/main/java/digit/util/MdmsUtil.java b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java similarity index 100% rename from health-services/output/src/main/java/digit/util/MdmsUtil.java rename to health-services/plan-service/src/main/java/digit/util/MdmsUtil.java diff --git a/health-services/output/src/main/java/digit/util/ResponseInfoFactory.java b/health-services/plan-service/src/main/java/digit/util/ResponseInfoFactory.java similarity index 100% rename from health-services/output/src/main/java/digit/util/ResponseInfoFactory.java rename to health-services/plan-service/src/main/java/digit/util/ResponseInfoFactory.java diff --git a/health-services/output/src/main/java/digit/util/UrlShortenerUtil.java b/health-services/plan-service/src/main/java/digit/util/UrlShortenerUtil.java similarity index 100% rename from health-services/output/src/main/java/digit/util/UrlShortenerUtil.java rename to health-services/plan-service/src/main/java/digit/util/UrlShortenerUtil.java diff --git a/health-services/output/src/main/java/digit/util/UserUtil.java b/health-services/plan-service/src/main/java/digit/util/UserUtil.java similarity index 100% rename from health-services/output/src/main/java/digit/util/UserUtil.java rename to health-services/plan-service/src/main/java/digit/util/UserUtil.java diff --git a/health-services/output/src/main/java/digit/util/WorkflowUtil.java b/health-services/plan-service/src/main/java/digit/util/WorkflowUtil.java similarity index 100% rename from health-services/output/src/main/java/digit/util/WorkflowUtil.java rename to health-services/plan-service/src/main/java/digit/util/WorkflowUtil.java diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/ConfigApiController.java b/health-services/plan-service/src/main/java/digit/web/controllers/ConfigApiController.java new file mode 100644 index 00000000000..49764139447 --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/web/controllers/ConfigApiController.java @@ -0,0 +1,60 @@ +package digit.web.controllers; + + +import digit.service.PlanConfigurationService; +import digit.web.models.PlanConfigurationRequest; +import digit.web.models.PlanConfigurationResponse; +import digit.web.models.PlanConfigurationSearchRequest; +import javax.validation.Valid; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestMapping; +import java.util.*; + +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Controller +@RequestMapping("/plan") +public class ConfigApiController { + + private final ObjectMapper objectMapper; + + private final PlanConfigurationService planConfigurationService; + + @Autowired + public ConfigApiController(ObjectMapper objectMapper, PlanConfigurationService planConfigurationService) { + this.objectMapper = objectMapper; + this.planConfigurationService = planConfigurationService; + } + + @RequestMapping(value = "/config/_create", method = RequestMethod.POST) + public ResponseEntity configCreatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationRequest body) { + + PlanConfigurationRequest planConfigurationRequest = planConfigurationService.create(body); + PlanConfigurationResponse response = PlanConfigurationResponse.builder() + .planConfigurationResponse(Collections.singletonList(planConfigurationRequest.getPlanConfiguration())) + .responseInfo(new ResponseInfo()) + .build(); + + return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); + + } + + @RequestMapping(value = "/config/_search", method = RequestMethod.POST) + public ResponseEntity configSearchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationSearchRequest body) { + return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanConfigurationResponse()); + } + + @RequestMapping(value = "/config/_update", method = RequestMethod.POST) + public ResponseEntity configUpdatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationRequest body) { + return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanConfigurationResponse()); + } +} diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/CreateApiController.java b/health-services/plan-service/src/main/java/digit/web/controllers/CreateApiController.java new file mode 100644 index 00000000000..acf18875b6a --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/web/controllers/CreateApiController.java @@ -0,0 +1,50 @@ +package digit.web.controllers; + + +import digit.web.models.ErrorRes; +import digit.web.models.PlanCreateRequest; +import digit.web.models.PlanSearchResponse; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.bind.annotation.RequestMapping; +import java.io.IOException; +import java.util.*; + +import javax.validation.constraints.*; +import javax.validation.Valid; +import javax.servlet.http.HttpServletRequest; +import java.util.Optional; + +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Controller +@RequestMapping("/plan") +public class CreateApiController { + + private final ObjectMapper objectMapper; + + @Autowired + public CreateApiController(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @RequestMapping(value = "/_create", method = RequestMethod.POST) + public ResponseEntity createPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanCreateRequest body) { + return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); + } + +} diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/SearchApiController.java b/health-services/plan-service/src/main/java/digit/web/controllers/SearchApiController.java new file mode 100644 index 00000000000..7628964670b --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/web/controllers/SearchApiController.java @@ -0,0 +1,51 @@ +package digit.web.controllers; + + +import digit.web.models.ErrorRes; +import digit.web.models.PlanSearchRequest; +import digit.web.models.PlanSearchResponse; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.bind.annotation.RequestMapping; +import java.io.IOException; +import java.util.*; + +import javax.validation.constraints.*; +import javax.validation.Valid; +import javax.servlet.http.HttpServletRequest; +import java.util.Optional; + +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Controller +@RequestMapping("/plan") +public class SearchApiController { + + private final ObjectMapper objectMapper; + + + @Autowired + public SearchApiController(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @RequestMapping(value = "/_search", method = RequestMethod.POST) + public ResponseEntity searchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanSearchRequest body) { + return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); + } + +} diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/UpdateApiController.java b/health-services/plan-service/src/main/java/digit/web/controllers/UpdateApiController.java new file mode 100644 index 00000000000..35eedfeeb6a --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/web/controllers/UpdateApiController.java @@ -0,0 +1,49 @@ +package digit.web.controllers; + + +import digit.web.models.ErrorRes; +import digit.web.models.PlanEditRequest; +import digit.web.models.PlanSearchResponse; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.bind.annotation.RequestMapping; +import java.io.IOException; +import java.util.*; + +import javax.validation.constraints.*; +import javax.validation.Valid; +import java.util.Optional; + +@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") +@Controller +@RequestMapping("/plan") +public class UpdateApiController { + + private final ObjectMapper objectMapper; + + @Autowired + public UpdateApiController(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @RequestMapping(value = "/_update", method = RequestMethod.POST) + public ResponseEntity updatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanEditRequest body) { + return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); + } + +} diff --git a/health-services/output/src/main/java/digit/web/models/Activity.java b/health-services/plan-service/src/main/java/digit/web/models/Activity.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/Activity.java rename to health-services/plan-service/src/main/java/digit/web/models/Activity.java diff --git a/health-services/output/src/main/java/digit/web/models/Assumption.java b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/Assumption.java rename to health-services/plan-service/src/main/java/digit/web/models/Assumption.java diff --git a/health-services/output/src/main/java/digit/web/models/Condition.java b/health-services/plan-service/src/main/java/digit/web/models/Condition.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/Condition.java rename to health-services/plan-service/src/main/java/digit/web/models/Condition.java diff --git a/health-services/output/src/main/java/digit/web/models/Error.java b/health-services/plan-service/src/main/java/digit/web/models/Error.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/Error.java rename to health-services/plan-service/src/main/java/digit/web/models/Error.java diff --git a/health-services/output/src/main/java/digit/web/models/ErrorRes.java b/health-services/plan-service/src/main/java/digit/web/models/ErrorRes.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/ErrorRes.java rename to health-services/plan-service/src/main/java/digit/web/models/ErrorRes.java diff --git a/health-services/output/src/main/java/digit/web/models/File.java b/health-services/plan-service/src/main/java/digit/web/models/File.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/File.java rename to health-services/plan-service/src/main/java/digit/web/models/File.java diff --git a/health-services/output/src/main/java/digit/web/models/Operation.java b/health-services/plan-service/src/main/java/digit/web/models/Operation.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/Operation.java rename to health-services/plan-service/src/main/java/digit/web/models/Operation.java diff --git a/health-services/output/src/main/java/digit/web/models/Plan.java b/health-services/plan-service/src/main/java/digit/web/models/Plan.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/Plan.java rename to health-services/plan-service/src/main/java/digit/web/models/Plan.java diff --git a/health-services/output/src/main/java/digit/web/models/PlanConfiguration.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/PlanConfiguration.java rename to health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java diff --git a/health-services/output/src/main/java/digit/web/models/PlanConfigurationRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/PlanConfigurationRequest.java rename to health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java diff --git a/health-services/output/src/main/java/digit/web/models/PlanConfigurationResponse.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/PlanConfigurationResponse.java rename to health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java diff --git a/health-services/output/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java rename to health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java diff --git a/health-services/output/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java rename to health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java diff --git a/health-services/output/src/main/java/digit/web/models/PlanCreateRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/PlanCreateRequest.java rename to health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java diff --git a/health-services/output/src/main/java/digit/web/models/PlanEditRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/PlanEditRequest.java rename to health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java diff --git a/health-services/output/src/main/java/digit/web/models/PlanSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/PlanSearchCriteria.java rename to health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java diff --git a/health-services/output/src/main/java/digit/web/models/PlanSearchRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/PlanSearchRequest.java rename to health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java diff --git a/health-services/output/src/main/java/digit/web/models/PlanSearchResponse.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchResponse.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/PlanSearchResponse.java rename to health-services/plan-service/src/main/java/digit/web/models/PlanSearchResponse.java diff --git a/health-services/output/src/main/java/digit/web/models/Resource.java b/health-services/plan-service/src/main/java/digit/web/models/Resource.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/Resource.java rename to health-services/plan-service/src/main/java/digit/web/models/Resource.java diff --git a/health-services/output/src/main/java/digit/web/models/ResourceMapping.java b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/ResourceMapping.java rename to health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java diff --git a/health-services/output/src/main/java/digit/web/models/Target.java b/health-services/plan-service/src/main/java/digit/web/models/Target.java similarity index 100% rename from health-services/output/src/main/java/digit/web/models/Target.java rename to health-services/plan-service/src/main/java/digit/web/models/Target.java diff --git a/health-services/output/src/main/resources/application.properties b/health-services/plan-service/src/main/resources/application.properties similarity index 95% rename from health-services/output/src/main/resources/application.properties rename to health-services/plan-service/src/main/resources/application.properties index 3aeb15f40fd..faf6fc9532e 100644 --- a/health-services/output/src/main/resources/application.properties +++ b/health-services/plan-service/src/main/resources/application.properties @@ -4,12 +4,12 @@ app.timezone=UTC #DATABASE CONFIGURATION spring.datasource.driver-class-name=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://localhost:5432/postgres +spring.datasource.url=jdbc:postgresql://localhost:5432/microplan spring.datasource.username=postgres spring.datasource.password=postgres #FLYWAY CONFIGURATION -spring.flyway.url=jdbc:postgresql://localhost:5432/postgres +spring.flyway.url=jdbc:postgresql://localhost:5432/microplan spring.flyway.user=postgres spring.flyway.password=postgres spring.flyway.table=public diff --git a/health-services/output/src/main/resources/db/Dockerfile b/health-services/plan-service/src/main/resources/db/Dockerfile similarity index 100% rename from health-services/output/src/main/resources/db/Dockerfile rename to health-services/plan-service/src/main/resources/db/Dockerfile diff --git a/health-services/output/src/main/resources/db/migrate.sh b/health-services/plan-service/src/main/resources/db/migrate.sh similarity index 100% rename from health-services/output/src/main/resources/db/migrate.sh rename to health-services/plan-service/src/main/resources/db/migrate.sh diff --git a/health-services/plan-service/src/main/resources/db/migration/main/V20240305113045__plan_configuration_create_ddl.sql b/health-services/plan-service/src/main/resources/db/migration/main/V20240305113045__plan_configuration_create_ddl.sql new file mode 100644 index 00000000000..5471368869b --- /dev/null +++ b/health-services/plan-service/src/main/resources/db/migration/main/V20240305113045__plan_configuration_create_ddl.sql @@ -0,0 +1,73 @@ +-- Table: plan_configuration +CREATE TABLE plan_configuration ( + id character varying(64), + tenant_id character varying(64), + name character varying(128), + execution_plan_id character varying(64), + created_by character varying(64), + created_time bigint, + last_modified_by character varying(64), + last_modified_time bigint, + CONSTRAINT uk_plan_configuration_id PRIMARY KEY (id) +); + + +-- Table: plan_configuration_files +CREATE TABLE plan_configuration_files ( + id character varying(64), + plan_configuration_id character varying(64), + filestore_id character varying(128), + input_file_type character varying(64), + created_by character varying(64), + created_time bigint, + last_modified_by character varying(64), + last_modified_time bigint, + CONSTRAINT uk_plan_configuration_files_id PRIMARY KEY (id), + FOREIGN KEY (plan_configuration_id) REFERENCES plan_configuration(id) +); + + +-- Table: plan_configuration_assumptions +CREATE TABLE plan_configuration_assumptions ( + id character varying(64), + key character varying(256), + value character varying(256), + plan_configuration_id character varying(64), + created_by character varying(64), + created_time bigint, + last_modified_by character varying(64), + last_modified_time bigint, + CONSTRAINT uk_plan_configuration_assumptions_id PRIMARY KEY (id), + FOREIGN KEY (plan_configuration_id) REFERENCES plan_configuration(id) +); + + +-- Table: plan_configuration_operations +CREATE TABLE plan_configuration_operations ( + id character varying(64), + input character varying(256), + operator character varying(64), + assumption_value bigint, + output character varying(64), + plan_configuration_id character varying(64), + created_by character varying(64), + created_time bigint, + last_modified_by character varying(64), + last_modified_time bigint, + CONSTRAINT uk_plan_configuration_operations_id PRIMARY KEY (id), + FOREIGN KEY (plan_configuration_id) REFERENCES plan_configuration(id) +); + + +-- Table: plan_configuration_mapping +CREATE TABLE plan_configuration_mapping ( + id character varying(64), + mapped_from character varying(256), + mapped_to character varying(256), + plan_configuration_id character varying(64), + created_by character varying(64), + created_time bigint, + last_modified_by character varying(64), + last_modified_time bigint, + CONSTRAINT uk_plan_configuration_mapping_id PRIMARY KEY (id) +); \ No newline at end of file diff --git a/health-services/output/src/test/java/digit/TestConfiguration.java b/health-services/plan-service/src/test/java/digit/TestConfiguration.java similarity index 100% rename from health-services/output/src/test/java/digit/TestConfiguration.java rename to health-services/plan-service/src/test/java/digit/TestConfiguration.java diff --git a/health-services/output/src/test/java/digit/web/controllers/ConfigApiControllerTest.java b/health-services/plan-service/src/test/java/digit/web/controllers/ConfigApiControllerTest.java similarity index 100% rename from health-services/output/src/test/java/digit/web/controllers/ConfigApiControllerTest.java rename to health-services/plan-service/src/test/java/digit/web/controllers/ConfigApiControllerTest.java diff --git a/health-services/output/src/test/java/digit/web/controllers/CreateApiControllerTest.java b/health-services/plan-service/src/test/java/digit/web/controllers/CreateApiControllerTest.java similarity index 100% rename from health-services/output/src/test/java/digit/web/controllers/CreateApiControllerTest.java rename to health-services/plan-service/src/test/java/digit/web/controllers/CreateApiControllerTest.java diff --git a/health-services/output/src/test/java/digit/web/controllers/SearchApiControllerTest.java b/health-services/plan-service/src/test/java/digit/web/controllers/SearchApiControllerTest.java similarity index 100% rename from health-services/output/src/test/java/digit/web/controllers/SearchApiControllerTest.java rename to health-services/plan-service/src/test/java/digit/web/controllers/SearchApiControllerTest.java diff --git a/health-services/output/src/test/java/digit/web/controllers/UpdateApiControllerTest.java b/health-services/plan-service/src/test/java/digit/web/controllers/UpdateApiControllerTest.java similarity index 100% rename from health-services/output/src/test/java/digit/web/controllers/UpdateApiControllerTest.java rename to health-services/plan-service/src/test/java/digit/web/controllers/UpdateApiControllerTest.java From 1d7b717748d3effbdab614dd5638178a1a12394e Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Tue, 5 Mar 2024 15:15:01 +0530 Subject: [PATCH 03/53] [HLM-5129] Cleaned up code for plan service --- .../src/main/java/digit/Main.java | 1 - .../web/controllers/CreateApiController.java | 50 ----------- ...troller.java => PlanConfigController.java} | 9 +- ...ApiController.java => PlanController.java} | 32 +++----- .../web/controllers/SearchApiController.java | 51 ------------ .../src/main/resources/application.properties | 38 ++------- .../main/V20240305113047__plan_create_ddl.sql | 82 +++++++++++++++++++ .../controllers/CreateApiControllerTest.java | 2 +- ...est.java => PlanConfigControllerTest.java} | 5 +- .../controllers/SearchApiControllerTest.java | 43 ---------- .../controllers/UpdateApiControllerTest.java | 43 ---------- 11 files changed, 108 insertions(+), 248 deletions(-) delete mode 100644 health-services/plan-service/src/main/java/digit/web/controllers/CreateApiController.java rename health-services/plan-service/src/main/java/digit/web/controllers/{ConfigApiController.java => PlanConfigController.java} (90%) rename health-services/plan-service/src/main/java/digit/web/controllers/{UpdateApiController.java => PlanController.java} (59%) delete mode 100644 health-services/plan-service/src/main/java/digit/web/controllers/SearchApiController.java create mode 100644 health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql rename health-services/plan-service/src/test/java/digit/web/controllers/{ConfigApiControllerTest.java => PlanConfigControllerTest.java} (94%) delete mode 100644 health-services/plan-service/src/test/java/digit/web/controllers/SearchApiControllerTest.java delete mode 100644 health-services/plan-service/src/test/java/digit/web/controllers/UpdateApiControllerTest.java diff --git a/health-services/plan-service/src/main/java/digit/Main.java b/health-services/plan-service/src/main/java/digit/Main.java index 6e3d79db11c..9ccda08d54e 100644 --- a/health-services/plan-service/src/main/java/digit/Main.java +++ b/health-services/plan-service/src/main/java/digit/Main.java @@ -12,7 +12,6 @@ @ComponentScan(basePackages = { "digit", "digit.web.controllers" , "digit.config"}) public class Main { - public static void main(String[] args) throws Exception { SpringApplication.run(Main.class, args); } diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/CreateApiController.java b/health-services/plan-service/src/main/java/digit/web/controllers/CreateApiController.java deleted file mode 100644 index acf18875b6a..00000000000 --- a/health-services/plan-service/src/main/java/digit/web/controllers/CreateApiController.java +++ /dev/null @@ -1,50 +0,0 @@ -package digit.web.controllers; - - -import digit.web.models.ErrorRes; -import digit.web.models.PlanCreateRequest; -import digit.web.models.PlanSearchResponse; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.media.Schema; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.bind.annotation.RequestMapping; -import java.io.IOException; -import java.util.*; - -import javax.validation.constraints.*; -import javax.validation.Valid; -import javax.servlet.http.HttpServletRequest; -import java.util.Optional; - -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") -@Controller -@RequestMapping("/plan") -public class CreateApiController { - - private final ObjectMapper objectMapper; - - @Autowired - public CreateApiController(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - } - - @RequestMapping(value = "/_create", method = RequestMethod.POST) - public ResponseEntity createPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanCreateRequest body) { - return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); - } - -} diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/ConfigApiController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java similarity index 90% rename from health-services/plan-service/src/main/java/digit/web/controllers/ConfigApiController.java rename to health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java index 49764139447..ce6bfdf0f36 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/ConfigApiController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java @@ -22,15 +22,14 @@ @javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Controller -@RequestMapping("/plan") -public class ConfigApiController { +public class PlanConfigController { - private final ObjectMapper objectMapper; + private ObjectMapper objectMapper; - private final PlanConfigurationService planConfigurationService; + private PlanConfigurationService planConfigurationService; @Autowired - public ConfigApiController(ObjectMapper objectMapper, PlanConfigurationService planConfigurationService) { + public PlanConfigController(ObjectMapper objectMapper, PlanConfigurationService planConfigurationService) { this.objectMapper = objectMapper; this.planConfigurationService = planConfigurationService; } diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/UpdateApiController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java similarity index 59% rename from health-services/plan-service/src/main/java/digit/web/controllers/UpdateApiController.java rename to health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java index 35eedfeeb6a..1428b306cad 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/UpdateApiController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java @@ -1,46 +1,40 @@ package digit.web.controllers; -import digit.web.models.ErrorRes; -import digit.web.models.PlanEditRequest; -import digit.web.models.PlanSearchResponse; +import digit.web.models.*; import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.media.Schema; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.multipart.MultipartFile; import org.springframework.web.bind.annotation.RequestMapping; -import java.io.IOException; -import java.util.*; -import javax.validation.constraints.*; import javax.validation.Valid; -import java.util.Optional; @javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Controller -@RequestMapping("/plan") -public class UpdateApiController { +public class PlanController { private final ObjectMapper objectMapper; - @Autowired - public UpdateApiController(ObjectMapper objectMapper) { + public PlanController(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } + @RequestMapping(value = "/_create", method = RequestMethod.POST) + public ResponseEntity createPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanCreateRequest body) { + return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); + } + + @RequestMapping(value = "/_search", method = RequestMethod.POST) + public ResponseEntity searchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanSearchRequest body) { + return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); + } + @RequestMapping(value = "/_update", method = RequestMethod.POST) public ResponseEntity updatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanEditRequest body) { return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/SearchApiController.java b/health-services/plan-service/src/main/java/digit/web/controllers/SearchApiController.java deleted file mode 100644 index 7628964670b..00000000000 --- a/health-services/plan-service/src/main/java/digit/web/controllers/SearchApiController.java +++ /dev/null @@ -1,51 +0,0 @@ -package digit.web.controllers; - - -import digit.web.models.ErrorRes; -import digit.web.models.PlanSearchRequest; -import digit.web.models.PlanSearchResponse; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.media.Schema; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.bind.annotation.RequestMapping; -import java.io.IOException; -import java.util.*; - -import javax.validation.constraints.*; -import javax.validation.Valid; -import javax.servlet.http.HttpServletRequest; -import java.util.Optional; - -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") -@Controller -@RequestMapping("/plan") -public class SearchApiController { - - private final ObjectMapper objectMapper; - - - @Autowired - public SearchApiController(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - } - - @RequestMapping(value = "/_search", method = RequestMethod.POST) - public ResponseEntity searchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanSearchRequest body) { - return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); - } - -} diff --git a/health-services/plan-service/src/main/resources/application.properties b/health-services/plan-service/src/main/resources/application.properties index faf6fc9532e..0192ed4b1bb 100644 --- a/health-services/plan-service/src/main/resources/application.properties +++ b/health-services/plan-service/src/main/resources/application.properties @@ -1,15 +1,18 @@ -server.contextPath=/plan-service server.port=8080 +server.servlet.context-path=/plan + +#MANAGEMENT ENDPOINT CONFIGURATION +management.endpoints.web.base-path=/ app.timezone=UTC #DATABASE CONFIGURATION spring.datasource.driver-class-name=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://localhost:5432/microplan +spring.datasource.url=jdbc:postgresql://localhost:5433/plandb spring.datasource.username=postgres spring.datasource.password=postgres #FLYWAY CONFIGURATION -spring.flyway.url=jdbc:postgresql://localhost:5432/microplan +spring.flyway.url=jdbc:postgresql://localhost:5433/plandb spring.flyway.user=postgres spring.flyway.password=postgres spring.flyway.table=public @@ -39,32 +42,10 @@ kafka.producer.config.batch_size_config=16384 kafka.producer.config.linger_ms_config=1 kafka.producer.config.buffer_memory_config=33554432 -#Localization config -egov.localization.host=https://dev.digit.org -egov.localization.workDir.path=/localization/messages/v1 -egov.localization.context.path=/localization/messages/v1 -egov.localization.search.endpoint=/_search -egov.localization.statelevel=true - #mdms urls egov.mdms.host=https://dev.digit.org egov.mdms.search.endpoint=/egov-mdms-service/v1/_search -#hrms urls -egov.hrms.host=https://dev.digit.org -egov.hrms.search.endpoint=/egov-hrms/employees/_search - -#User config -egov.user.host=https://dev.digit.org -egov.user.context.path=/user/users -egov.user.create.path=/_createnovalidate -egov.user.search.path=/user/_search -egov.user.update.path=/_updatenovalidate - -#Idgen Config -egov.idgen.host=https://dev.digit.org/ -egov.idgen.path=egov-idgen/id/_generate - #Workflow config is.workflow.enabled=true egov.workflow.host=https://dev.digit.org @@ -72,12 +53,5 @@ egov.workflow.transition.path=/egov-workflow-v2/egov-wf/process/_transition egov.workflow.businessservice.search.path=/egov-workflow-v2/egov-wf/businessservice/_search egov.workflow.processinstance.search.path=/egov-workflow-v2/egov-wf/process/_search -#url shortner -egov.url.shortner.host=https://dev.digit.org -egov.url.shortner.endpoint=/egov-url-shortening/shortener - -egov.sms.notification.topic=egov.core.notification.sms -kafka.topics.receipt.create=dss-collection - # The value of the following field should be changed to service specific name kafka.topics.consumer=service-consumer-topic \ No newline at end of file diff --git a/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql b/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql new file mode 100644 index 00000000000..fa244addcb1 --- /dev/null +++ b/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql @@ -0,0 +1,82 @@ +CREATE TABLE plan ( + id varchar(64), + tenant_id varchar(64), + locality varchar(64), + execution_plan_id varchar(64), + plan_configuration_id varchar(64), + additional_details JSONB, + created_by varchar(64), + created_time bigint, + last_modified_by varchar(64), + last_modified_time bigint, + CONSTRAINT uk_plan_id PRIMARY KEY (id) +); + +CREATE TABLE plan_activity ( + id varchar(64), + tenant_id varchar(64), + description varchar(2048), + planned_start_date bigint, + planned_end_date bigint, + plan_id varchar(64), + resource_id varchar(64), + created_by varchar(64), + created_time bigint, + last_modified_by varchar(64), + last_modified_time bigint, + CONSTRAINT uk_plan_activity_id PRIMARY KEY (id), + FOREIGN KEY (plan_id) REFERENCES plan(id) +); + +CREATE TABLE plan_activity_dependency ( + id varchar(64), + activity_id varchar(64), + precursor_activity_id varchar(64), + created_by varchar(64), + created_time bigint, + last_modified_by varchar(64), + last_modified_time bigint, + CONSTRAINT uk_plan_activity_dependency_id PRIMARY KEY (id), + FOREIGN KEY (activity_id) REFERENCES plan(id) +); + +CREATE TABLE plan_activity_condition ( + id varchar(64), + entity varchar(64), + entity_property varchar(64), + expression varchar(2048), + activity_id varchar(64), + created_by varchar(64), + created_time bigint, + last_modified_by varchar(64), + last_modified_time bigint, + CONSTRAINT uk_plan_activity_condition_id PRIMARY KEY (id), + FOREIGN KEY (activity_id) REFERENCES plan(id) +); + +CREATE TABLE plan_resource ( + id varchar(64), + resource_type varchar(256), + estimated_number numeric(12,2), + plan_id varchar(64), + created_by varchar(64), + created_time bigint, + last_modified_by varchar(64), + last_modified_time bigint, + CONSTRAINT uk_plan_resource_id PRIMARY KEY (id) +); + +CREATE TABLE plan_target ( + id varchar(64), + metric varchar(128), + metric_value numeric(12,2), + metric_comparator varchar(64), + metric_unit varchar(128), + plan_id varchar(64), + created_by varchar(64), + created_time bigint, + last_modified_by varchar(64), + last_modified_time bigint, + CONSTRAINT uk_plan_target_id PRIMARY KEY (id), + FOREIGN KEY (plan_id) REFERENCES plan(id) +); \ No newline at end of file diff --git a/health-services/plan-service/src/test/java/digit/web/controllers/CreateApiControllerTest.java b/health-services/plan-service/src/test/java/digit/web/controllers/CreateApiControllerTest.java index 8f26c9fb211..0826f5c88f6 100644 --- a/health-services/plan-service/src/test/java/digit/web/controllers/CreateApiControllerTest.java +++ b/health-services/plan-service/src/test/java/digit/web/controllers/CreateApiControllerTest.java @@ -19,7 +19,7 @@ */ @Ignore @RunWith(SpringRunner.class) -@WebMvcTest(CreateApiController.class) +@WebMvcTest(PlanController.class) @Import(TestConfiguration.class) public class CreateApiControllerTest { diff --git a/health-services/plan-service/src/test/java/digit/web/controllers/ConfigApiControllerTest.java b/health-services/plan-service/src/test/java/digit/web/controllers/PlanConfigControllerTest.java similarity index 94% rename from health-services/plan-service/src/test/java/digit/web/controllers/ConfigApiControllerTest.java rename to health-services/plan-service/src/test/java/digit/web/controllers/PlanConfigControllerTest.java index 601fe9a0834..03fbbd0c8ed 100644 --- a/health-services/plan-service/src/test/java/digit/web/controllers/ConfigApiControllerTest.java +++ b/health-services/plan-service/src/test/java/digit/web/controllers/PlanConfigControllerTest.java @@ -6,7 +6,6 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.context.annotation.Import; -import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -20,9 +19,9 @@ */ @Ignore @RunWith(SpringRunner.class) -@WebMvcTest(ConfigApiController.class) +@WebMvcTest(PlanConfigController.class) @Import(TestConfiguration.class) -public class ConfigApiControllerTest { +public class PlanConfigControllerTest { @Autowired private MockMvc mockMvc; diff --git a/health-services/plan-service/src/test/java/digit/web/controllers/SearchApiControllerTest.java b/health-services/plan-service/src/test/java/digit/web/controllers/SearchApiControllerTest.java deleted file mode 100644 index de1aac63955..00000000000 --- a/health-services/plan-service/src/test/java/digit/web/controllers/SearchApiControllerTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package digit.web.controllers; - -import org.junit.Test; -import org.junit.Ignore; -import org.junit.runner.RunWith; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.context.annotation.Import; -import org.springframework.http.MediaType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import digit.TestConfiguration; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** -* API tests for SearchApiController -*/ -@Ignore -@RunWith(SpringRunner.class) -@WebMvcTest(SearchApiController.class) -@Import(TestConfiguration.class) -public class SearchApiControllerTest { - - @Autowired - private MockMvc mockMvc; - - @Test - public void searchPostSuccess() throws Exception { - mockMvc.perform(post("/plan/_search").contentType(MediaType - .APPLICATION_JSON_UTF8)) - .andExpect(status().isOk()); - } - - @Test - public void searchPostFailure() throws Exception { - mockMvc.perform(post("/plan/_search").contentType(MediaType - .APPLICATION_JSON_UTF8)) - .andExpect(status().isBadRequest()); - } - -} diff --git a/health-services/plan-service/src/test/java/digit/web/controllers/UpdateApiControllerTest.java b/health-services/plan-service/src/test/java/digit/web/controllers/UpdateApiControllerTest.java deleted file mode 100644 index c5c5f3d8f29..00000000000 --- a/health-services/plan-service/src/test/java/digit/web/controllers/UpdateApiControllerTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package digit.web.controllers; - - -import org.junit.Ignore; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.context.annotation.Import; -import org.springframework.http.MediaType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import digit.TestConfiguration; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** -* API tests for UpdateApiController -*/ -@Ignore -@RunWith(SpringRunner.class) -@WebMvcTest(UpdateApiController.class) -@Import(TestConfiguration.class) -public class UpdateApiControllerTest { - - @Autowired - private MockMvc mockMvc; - - @Test - public void updatePostSuccess() throws Exception { - mockMvc.perform(post("/plan/_update").contentType(MediaType - .APPLICATION_JSON_UTF8)) - .andExpect(status().isOk()); - } - - @Test - public void updatePostFailure() throws Exception { - mockMvc.perform(post("/plan/_update").contentType(MediaType - .APPLICATION_JSON_UTF8)) - .andExpect(status().isBadRequest()); - } - -} From c9f2f2731826f5f8921c7bb67a410a8a37d32a7d Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 5 Mar 2024 15:37:27 +0530 Subject: [PATCH 04/53] HLM-5117 Formatting all models --- health-services/plan-service/pom.xml | 6 + .../main/java/digit/config/Configuration.java | 8 +- .../java/digit/service/EnrichmentService.java | 17 ++- .../service/PlanConfigurationService.java | 29 ++++- .../PlanConfigurationValidator.java | 14 +++ .../java/digit/web/models/Assumption.java | 34 +++--- .../src/main/java/digit/web/models/Error.java | 3 - .../main/java/digit/web/models/ErrorRes.java | 25 ++-- .../src/main/java/digit/web/models/File.java | 80 +++++++------ .../main/java/digit/web/models/Operation.java | 113 +++++++++--------- .../src/main/java/digit/web/models/Plan.java | 77 ++++++------ .../digit/web/models/PlanConfiguration.java | 79 ++++++------ .../web/models/PlanConfigurationRequest.java | 18 ++- .../web/models/PlanConfigurationResponse.java | 23 ++-- .../PlanConfigurationSearchCriteria.java | 18 ++- .../PlanConfigurationSearchRequest.java | 16 ++- .../digit/web/models/PlanCreateRequest.java | 16 ++- .../digit/web/models/PlanEditRequest.java | 16 ++- .../digit/web/models/PlanSearchCriteria.java | 18 ++- .../digit/web/models/PlanSearchRequest.java | 16 ++- .../digit/web/models/PlanSearchResponse.java | 23 ++-- .../main/java/digit/web/models/Resource.java | 21 ++-- .../digit/web/models/ResourceMapping.java | 14 ++- .../main/java/digit/web/models/Target.java | 26 ++-- .../src/main/resources/application.properties | 4 + 25 files changed, 374 insertions(+), 340 deletions(-) create mode 100644 health-services/plan-service/src/main/java/digit/validators/PlanConfigurationValidator.java diff --git a/health-services/plan-service/pom.xml b/health-services/plan-service/pom.xml index 40396f5d3c1..9d6f849d021 100644 --- a/health-services/plan-service/pom.xml +++ b/health-services/plan-service/pom.xml @@ -116,6 +116,12 @@ junit test + + org.egov.common + health-services-common + 1.0.15-SNAPSHOT + compile + diff --git a/health-services/plan-service/src/main/java/digit/config/Configuration.java b/health-services/plan-service/src/main/java/digit/config/Configuration.java index d428c00d54b..b417d934c1b 100644 --- a/health-services/plan-service/src/main/java/digit/config/Configuration.java +++ b/health-services/plan-service/src/main/java/digit/config/Configuration.java @@ -85,8 +85,10 @@ public class Configuration { @Value("${egov.url.shortner.endpoint}") private String urlShortnerEndpoint; + //Persister Topic + @Value("${plan.configuration.create.topic}") + private String planConfigCreateTopic; - //SMSNotification - @Value("${egov.sms.notification.topic}") - private String smsNotificationTopic; + @Value("${plan.configuration.update.topic}") + private String planConfigUpdateTopic; } diff --git a/health-services/plan-service/src/main/java/digit/service/EnrichmentService.java b/health-services/plan-service/src/main/java/digit/service/EnrichmentService.java index 633e24a1c62..a0c4067908f 100644 --- a/health-services/plan-service/src/main/java/digit/service/EnrichmentService.java +++ b/health-services/plan-service/src/main/java/digit/service/EnrichmentService.java @@ -2,6 +2,7 @@ import digit.config.Configuration; import digit.config.ServiceConstants; +import digit.models.coremodels.AuditDetails; import digit.util.IdgenUtil; import digit.web.models.Assumption; import digit.web.models.Operation; @@ -26,13 +27,14 @@ public EnrichmentService(IdgenUtil idgenUtil, Configuration config) { this.config = config; } - public void create(PlanConfigurationRequest request) throws Exception { + public void enrichCreate(PlanConfigurationRequest request) { enrichPlanConfiguration(request.getPlanConfiguration()); - log.info("enriching facility enrichment with generated IDs"); } - public static PlanConfiguration enrichPlanConfiguration(PlanConfiguration planConfiguration) { + public PlanConfiguration enrichPlanConfiguration(PlanConfiguration planConfiguration) { + log.info("enriching plan config with generated IDs"); + // Set ID for PlanConfiguration planConfiguration.setId(UUID.randomUUID()); @@ -50,4 +52,13 @@ public static PlanConfiguration enrichPlanConfiguration(PlanConfiguration planCo return planConfiguration; } + + public AuditDetails getAuditDetails(String by, AuditDetails auditDetails, Boolean isCreate) { + Long time = System.currentTimeMillis(); + if (isCreate) + return AuditDetails.builder().createdBy(by).lastModifiedBy(by).createdTime(time).lastModifiedTime(time).build(); + else + return AuditDetails.builder().createdBy(auditDetails.getCreatedBy()).lastModifiedBy(by) + .createdTime(auditDetails.getCreatedTime()).lastModifiedTime(time).build(); + } } diff --git a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java index 39242237fb9..21ed5e076f1 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java @@ -1,9 +1,10 @@ package digit.service; -import digit.web.models.PlanConfiguration; +import digit.config.Configuration; +import digit.validators.PlanConfigurationValidator; import digit.web.models.PlanConfigurationRequest; -import java.util.List; -import java.util.Map; + +import org.egov.common.producer.Producer; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -13,12 +14,28 @@ public class PlanConfigurationService { @Autowired - public PlanConfigurationService() { + private final Producer producer; + + @Autowired + private final EnrichmentService enrichmentService; + + @Autowired + private final Configuration config; + + @Autowired + private final PlanConfigurationValidator validator; + + public PlanConfigurationService(Producer producer, EnrichmentService enrichmentService, Configuration config, PlanConfigurationValidator validator) { + this.producer = producer; + this.enrichmentService = enrichmentService; + this.config = config; + this.validator = validator; } public PlanConfigurationRequest create(PlanConfigurationRequest request) { - log.info("received request to create plan configurations"); - + enrichmentService.enrichCreate(request); + validator.validateCreate(request); + producer.push(config.getPlanConfigCreateTopic() ,request); return new PlanConfigurationRequest(); } } \ No newline at end of file diff --git a/health-services/plan-service/src/main/java/digit/validators/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/validators/PlanConfigurationValidator.java new file mode 100644 index 00000000000..448d9936ebd --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/validators/PlanConfigurationValidator.java @@ -0,0 +1,14 @@ +package digit.validators; + +import digit.web.models.PlanConfigurationRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +public class PlanConfigurationValidator { + + public void validateCreate(PlanConfigurationRequest request) { +// enrichPlanConfiguration(request.getPlanConfiguration()); + } +} diff --git a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java index 42855f8221d..537d92d1671 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java @@ -1,5 +1,6 @@ package digit.web.models; +import digit.models.coremodels.AuditDetails; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; @@ -23,22 +24,23 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class Assumption { - @JsonProperty("id") - - @Valid - private UUID id = null; - - @JsonProperty("key") - @NotNull - - @Size(min=1,max=32) private String key = null; - - @JsonProperty("value") - @NotNull - - @Valid - private BigDecimal value = null; +public class Assumption { + @JsonProperty("id") + @Valid + private UUID id = null; + + @JsonProperty("key") + @NotNull + @Size(min = 1, max = 32) + private String key = null; + + @JsonProperty("value") + @NotNull + @Valid + private BigDecimal value = null; + + @JsonProperty("auditDetails") + private @Valid AuditDetails auditDetails; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Error.java b/health-services/plan-service/src/main/java/digit/web/models/Error.java index b83266d0b25..fca85a2f76f 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Error.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Error.java @@ -31,15 +31,12 @@ public class Error { @JsonProperty("message") @NotNull - private String message = null; @JsonProperty("description") - private String description = null; @JsonProperty("params") - private List params = null; diff --git a/health-services/plan-service/src/main/java/digit/web/models/ErrorRes.java b/health-services/plan-service/src/main/java/digit/web/models/ErrorRes.java index 00ac425e528..bde3acbc471 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/ErrorRes.java +++ b/health-services/plan-service/src/main/java/digit/web/models/ErrorRes.java @@ -23,24 +23,23 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class ErrorRes { - @JsonProperty("ResponseInfo") - @NotNull +public class ErrorRes { + @JsonProperty("ResponseInfo") + @NotNull + @Valid + private ResponseInfo responseInfo = null; - @Valid - private ResponseInfo responseInfo = null; + @JsonProperty("Errors") + @Valid + private List errors = null; - @JsonProperty("Errors") - @Valid - private List errors = null; - - public ErrorRes addErrorsItem(Error errorsItem) { - if (this.errors == null) { + public ErrorRes addErrorsItem(Error errorsItem) { + if (this.errors == null) { this.errors = new ArrayList<>(); - } + } this.errors.add(errorsItem); return this; - } + } } diff --git a/health-services/plan-service/src/main/java/digit/web/models/File.java b/health-services/plan-service/src/main/java/digit/web/models/File.java index af73c7036e8..f03d1c68c3b 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/File.java +++ b/health-services/plan-service/src/main/java/digit/web/models/File.java @@ -1,5 +1,6 @@ package digit.web.models; +import digit.models.coremodels.AuditDetails; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; @@ -23,52 +24,55 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class File { - @JsonProperty("id") +public class File { + @JsonProperty("id") + @Valid + private UUID id = null; - @Valid - private UUID id = null; + @JsonProperty("filestoreId") + @NotNull + @Size(min = 1, max = 32) + private String filestoreId = null; - @JsonProperty("filestoreId") - @NotNull + @JsonProperty("inputFileType") + @NotNull + private InputFileTypeEnum inputFileType = null; - @Size(min=1,max=32) private String filestoreId = null; + @JsonProperty("auditDetails") + private @Valid AuditDetails auditDetails; - /** - * The original file type of the Input - */ - public enum InputFileTypeEnum { - EXCEL("Excel"), - - SHAPEFILE("Shapefile"), - - GEOJSON("GeoJSON"); - - private String value; - - InputFileTypeEnum(String value) { + + /** + * The original file type of the Input + */ + public enum InputFileTypeEnum { + EXCEL("Excel"), + + SHAPEFILE("Shapefile"), + + GEOJSON("GeoJSON"); + + private String value; + + InputFileTypeEnum(String value) { this.value = value; - } - - @Override - @JsonValue - public String toString() { + } + + @Override + @JsonValue + public String toString() { return String.valueOf(value); - } - - @JsonCreator - public static InputFileTypeEnum fromValue(String text) { + } + + @JsonCreator + public static InputFileTypeEnum fromValue(String text) { for (InputFileTypeEnum b : InputFileTypeEnum.values()) { - if (String.valueOf(b.value).equals(text)) { - return b; - } + if (String.valueOf(b.value).equals(text)) { + return b; + } } return null; - } - } @JsonProperty("inputFileType") - @NotNull - - private InputFileTypeEnum inputFileType = null; - + } + } } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Operation.java b/health-services/plan-service/src/main/java/digit/web/models/Operation.java index c77e9f8015b..13d8a965def 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Operation.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Operation.java @@ -1,5 +1,6 @@ package digit.web.models; +import digit.models.coremodels.AuditDetails; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; @@ -23,66 +24,68 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class Operation { - @JsonProperty("id") - - @Valid - private UUID id = null; - - @JsonProperty("input") - @NotNull - - @Size(min=1,max=32) private String input = null; - - /** - * The operator used in the operation - */ - public enum OperatorEnum { - PLUS("+"), - - MINUS("-"), - - SLASH("/"), - - STAR("*"), - - PERCENT("%"), - - _U("**"); - - private String value; - - OperatorEnum(String value) { - this.value = value; - } - - @Override - @JsonValue - public String toString() { - return String.valueOf(value); - } - - @JsonCreator - public static OperatorEnum fromValue(String text) { - for (OperatorEnum b : OperatorEnum.values()) { - if (String.valueOf(b.value).equals(text)) { - return b; - } - } - return null; - } - } @JsonProperty("operator") - @NotNull +public class Operation { + @JsonProperty("id") + @Valid + private UUID id = null; + + @JsonProperty("input") + @NotNull + @Size(min = 1, max = 32) + private String input = null; + + @JsonProperty("operator") + @NotNull + private OperatorEnum operator = null; + + @JsonProperty("assumptionValue") + private String assumptionValue = null; - private OperatorEnum operator = null; + @JsonProperty("output") + @Size(min = 1, max = 32) + private String output = null; - @JsonProperty("assumptionValue") + @JsonProperty("auditDetails") + private @Valid AuditDetails auditDetails; - private String assumptionValue = null; - @JsonProperty("output") + /** + * The operator used in the operation + */ + public enum OperatorEnum { + PLUS("+"), - @Size(min=1,max=32) private String output = null; + MINUS("-"), + SLASH("/"), + + STAR("*"), + + PERCENT("%"), + + _U("**"); + + private String value; + + OperatorEnum(String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static OperatorEnum fromValue(String text) { + for (OperatorEnum b : OperatorEnum.values()) { + if (String.valueOf(b.value).equals(text)) { + return b; + } + } + return null; + } + } } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Plan.java b/health-services/plan-service/src/main/java/digit/web/models/Plan.java index f5594178dec..8f877d0f99a 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Plan.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Plan.java @@ -27,67 +27,62 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class Plan { - @JsonProperty("id") +public class Plan { + @JsonProperty("id") + @Valid + private UUID id = null; - @Valid - private UUID id = null; + @JsonProperty("tenantId") + private String tenantId = null; - @JsonProperty("tenantId") + @JsonProperty("locality") + @Size(min = 2) + private String locality = null; - private String tenantId = null; + @JsonProperty("executionPlanId") + private String executionPlanId = null; - @JsonProperty("locality") + @JsonProperty("planConfigurationId") + private String planConfigurationId = null; - @Size(min=2) private String locality = null; + @JsonProperty("additionalDetails") + private Object additionalDetails = null; - @JsonProperty("executionPlanId") + @JsonProperty("activities") + @Valid + private List activities = null; - private String executionPlanId = null; + @JsonProperty("resources") + @Valid + private List resources = null; - @JsonProperty("planConfigurationId") + @JsonProperty("targets") + @Valid + private List targets = null; - private String planConfigurationId = null; - @JsonProperty("additionalDetails") - - private Object additionalDetails = null; - - @JsonProperty("activities") - @Valid - private List activities = null; - - @JsonProperty("resources") - @Valid - private List resources = null; - - @JsonProperty("targets") - @Valid - private List targets = null; - - - public Plan addActivitiesItem(Activity activitiesItem) { - if (this.activities == null) { + public Plan addActivitiesItem(Activity activitiesItem) { + if (this.activities == null) { this.activities = new ArrayList<>(); - } + } this.activities.add(activitiesItem); return this; - } + } - public Plan addResourcesItem(Resource resourcesItem) { - if (this.resources == null) { + public Plan addResourcesItem(Resource resourcesItem) { + if (this.resources == null) { this.resources = new ArrayList<>(); - } + } this.resources.add(resourcesItem); return this; - } + } - public Plan addTargetsItem(Target targetsItem) { - if (this.targets == null) { + public Plan addTargetsItem(Target targetsItem) { + if (this.targets == null) { this.targets = new ArrayList<>(); - } + } this.targets.add(targetsItem); return this; - } + } } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java index e3822ca1782..be314638555 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java @@ -1,5 +1,6 @@ package digit.web.models; +import digit.models.coremodels.AuditDetails; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; @@ -28,65 +29,65 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PlanConfiguration { - @JsonProperty("id") +public class PlanConfiguration { + @JsonProperty("id") - @Valid - private UUID id = null; + @Valid + private UUID id = null; - @JsonProperty("tenantId") - @NotNull + @JsonProperty("tenantId") + @NotNull + private String tenantId = null; - private String tenantId = null; + @JsonProperty("name") + @NotNull + @Size(min = 2) + private String name = null; - @JsonProperty("name") - @NotNull + @JsonProperty("executionPlanId") + private String executionPlanId = null; - @Size(min=2) private String name = null; + @JsonProperty("files") + @NotNull + @Valid + private List files = new ArrayList<>(); - @JsonProperty("executionPlanId") + @JsonProperty("assumptions") + @NotNull + @Valid + private List assumptions = new ArrayList<>(); - private String executionPlanId = null; + @JsonProperty("operations") + @NotNull + @Valid + private List operations = new ArrayList<>(); - @JsonProperty("files") - @NotNull - @Valid - private List files = new ArrayList<>(); + @JsonProperty("resourceMapping") + @NotNull + @Valid + private List resourceMapping = new ArrayList<>(); - @JsonProperty("assumptions") - @NotNull - @Valid - private List assumptions = new ArrayList<>(); + @JsonProperty("auditDetails") + private @Valid AuditDetails auditDetails; - @JsonProperty("operations") - @NotNull - @Valid - private List operations = new ArrayList<>(); - - @JsonProperty("resourceMapping") - @NotNull - @Valid - private List resourceMapping = new ArrayList<>(); - - - public PlanConfiguration addFilesItem(File filesItem) { + public PlanConfiguration addFilesItem(File filesItem) { this.files.add(filesItem); return this; - } + } - public PlanConfiguration addAssumptionsItem(Assumption assumptionsItem) { + public PlanConfiguration addAssumptionsItem(Assumption assumptionsItem) { this.assumptions.add(assumptionsItem); return this; - } + } - public PlanConfiguration addOperationsItem(Operation operationsItem) { + public PlanConfiguration addOperationsItem(Operation operationsItem) { this.operations.add(operationsItem); return this; - } + } - public PlanConfiguration addResourceMappingItem(ResourceMapping resourceMappingItem) { + public PlanConfiguration addResourceMappingItem(ResourceMapping resourceMappingItem) { this.resourceMapping.add(resourceMappingItem); return this; - } + } } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java index c1b14afc589..46319d45367 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java @@ -19,16 +19,14 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PlanConfigurationRequest { - @JsonProperty("RequestInfo") - - @Valid - private RequestInfo requestInfo = null; - - @JsonProperty("PlanConfiguration") - - @Valid - private PlanConfiguration planConfiguration = null; +public class PlanConfigurationRequest { + @JsonProperty("RequestInfo") + @Valid + private RequestInfo requestInfo = null; + + @JsonProperty("PlanConfiguration") + @Valid + private PlanConfiguration planConfiguration = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java index 2559cd16187..b6331b2f31d 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java @@ -20,23 +20,22 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PlanConfigurationResponse { - @JsonProperty("ResponseInfo") +public class PlanConfigurationResponse { + @JsonProperty("ResponseInfo") + @Valid + private ResponseInfo responseInfo = null; - @Valid - private ResponseInfo responseInfo = null; + @JsonProperty("PlanConfigurationResponse") + @Valid + private List planConfigurationResponse = null; - @JsonProperty("PlanConfigurationResponse") - @Valid - private List planConfigurationResponse = null; - - public PlanConfigurationResponse addPlanConfigurationResponseItem(PlanConfiguration planConfigurationResponseItem) { - if (this.planConfigurationResponse == null) { + public PlanConfigurationResponse addPlanConfigurationResponseItem(PlanConfiguration planConfigurationResponseItem) { + if (this.planConfigurationResponse == null) { this.planConfigurationResponse = new ArrayList<>(); - } + } this.planConfigurationResponse.add(planConfigurationResponseItem); return this; - } + } } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java index 4ab40c234a2..6e580e85f0a 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java @@ -21,18 +21,16 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PlanConfigurationSearchCriteria { - @JsonProperty("tenantId") +public class PlanConfigurationSearchCriteria { + @JsonProperty("tenantId") + @Size(min = 1, max = 100) + private String tenantId = null; - @Size(min=1,max=100) private String tenantId = null; + @JsonProperty("name") + private String name = null; - @JsonProperty("name") - - private String name = null; - - @JsonProperty("executionPlan") - - private String executionPlan = null; + @JsonProperty("executionPlan") + private String executionPlan = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java index b46d9cdb675..114f10e1d9e 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java @@ -18,16 +18,14 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PlanConfigurationSearchRequest { - @JsonProperty("RequestInfo") +public class PlanConfigurationSearchRequest { + @JsonProperty("RequestInfo") + @Valid + private RequestInfo requestInfo = null; - @Valid - private RequestInfo requestInfo = null; - - @JsonProperty("PlanConfigurationSearchCriteria") - - @Valid - private PlanConfigurationSearchCriteria planConfigurationSearchCriteria = null; + @JsonProperty("PlanConfigurationSearchCriteria") + @Valid + private PlanConfigurationSearchCriteria planConfigurationSearchCriteria = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java index 14d8559fdce..72d2654fa93 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java @@ -18,16 +18,14 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PlanCreateRequest { - @JsonProperty("RequestInfo") +public class PlanCreateRequest { + @JsonProperty("RequestInfo") + @Valid + private RequestInfo requestInfo = null; - @Valid - private RequestInfo requestInfo = null; - - @JsonProperty("Plan") - - @Valid - private Plan plan = null; + @JsonProperty("Plan") + @Valid + private Plan plan = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java index 91492c58575..28e985ef587 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java @@ -18,16 +18,14 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PlanEditRequest { - @JsonProperty("RequestInfo") +public class PlanEditRequest { + @JsonProperty("RequestInfo") + @Valid + private RequestInfo requestInfo = null; - @Valid - private RequestInfo requestInfo = null; - - @JsonProperty("Plan") - - @Valid - private Plan plan = null; + @JsonProperty("Plan") + @Valid + private Plan plan = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java index d520e9f899c..1cef6760225 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java @@ -21,18 +21,16 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PlanSearchCriteria { - @JsonProperty("tenantId") +public class PlanSearchCriteria { + @JsonProperty("tenantId") + @Size(min = 1, max = 100) + private String tenantId = null; - @Size(min=1,max=100) private String tenantId = null; + @JsonProperty("locality") + private String locality = null; - @JsonProperty("locality") - - private String locality = null; - - @JsonProperty("executionPlanId") - - private String executionPlanId = null; + @JsonProperty("executionPlanId") + private String executionPlanId = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java index f911e1c1e7b..fee09f5bf00 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java @@ -18,16 +18,14 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PlanSearchRequest { - @JsonProperty("RequestInfo") +public class PlanSearchRequest { + @JsonProperty("RequestInfo") + @Valid + private RequestInfo requestInfo = null; - @Valid - private RequestInfo requestInfo = null; - - @JsonProperty("PlanSearchCriteria") - - @Valid - private PlanSearchCriteria planSearchCriteria = null; + @JsonProperty("PlanSearchCriteria") + @Valid + private PlanSearchCriteria planSearchCriteria = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchResponse.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchResponse.java index 0e9a5e17d4e..4cabb5f4593 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchResponse.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchResponse.java @@ -20,23 +20,22 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PlanSearchResponse { - @JsonProperty("ResponseInfo") +public class PlanSearchResponse { + @JsonProperty("ResponseInfo") + @Valid + private ResponseInfo responseInfo = null; - @Valid - private ResponseInfo responseInfo = null; + @JsonProperty("Plan") + @Valid + private List plan = null; - @JsonProperty("Plan") - @Valid - private List plan = null; - - public PlanSearchResponse addPlanItem(Plan planItem) { - if (this.plan == null) { + public PlanSearchResponse addPlanItem(Plan planItem) { + if (this.plan == null) { this.plan = new ArrayList<>(); - } + } this.plan.add(planItem); return this; - } + } } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Resource.java b/health-services/plan-service/src/main/java/digit/web/models/Resource.java index 60f920327fc..1d812abc757 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Resource.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Resource.java @@ -23,20 +23,17 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class Resource { - @JsonProperty("id") +public class Resource { + @JsonProperty("id") + @Valid + private UUID id = null; - @Valid - private UUID id = null; + @JsonProperty("resourceType") + private String resourceType = null; - @JsonProperty("resourceType") - - private String resourceType = null; - - @JsonProperty("estimatedNumber") - - @Valid - private BigDecimal estimatedNumber = null; + @JsonProperty("estimatedNumber") + @Valid + private BigDecimal estimatedNumber = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java index 7fa024f7ad6..56859baa4b2 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java +++ b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java @@ -1,5 +1,6 @@ package digit.web.models; +import digit.models.coremodels.AuditDetails; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; @@ -21,14 +22,15 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class ResourceMapping { - @JsonProperty("mappedFrom") +public class ResourceMapping { + @JsonProperty("mappedFrom") + private String mappedFrom = null; - private String mappedFrom = null; + @JsonProperty("mappedTo") + private String mappedTo = null; - @JsonProperty("mappedTo") - - private String mappedTo = null; + @JsonProperty("auditDetails") + private @Valid AuditDetails auditDetails; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Target.java b/health-services/plan-service/src/main/java/digit/web/models/Target.java index 2c5d1333b62..f153ecbe190 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Target.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Target.java @@ -22,24 +22,20 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class Target { - @JsonProperty("id") +public class Target { + @JsonProperty("id") + @Valid + private UUID id = null; - @Valid - private UUID id = null; + @JsonProperty("taskId") + @Valid + private UUID taskId = null; - @JsonProperty("taskId") + @JsonProperty("metric") + private String metric = null; - @Valid - private UUID taskId = null; - - @JsonProperty("metric") - - private String metric = null; - - @JsonProperty("metricDetail") - - private Object metricDetail = null; + @JsonProperty("metricDetail") + private Object metricDetail = null; } diff --git a/health-services/plan-service/src/main/resources/application.properties b/health-services/plan-service/src/main/resources/application.properties index faf6fc9532e..00b1df8700f 100644 --- a/health-services/plan-service/src/main/resources/application.properties +++ b/health-services/plan-service/src/main/resources/application.properties @@ -39,6 +39,10 @@ kafka.producer.config.batch_size_config=16384 kafka.producer.config.linger_ms_config=1 kafka.producer.config.buffer_memory_config=33554432 +# PERSISTER KAFKA TOPICS +plan.configuration.create.topic=plan-config-create-topic +plan.configuration.update.topic=plan-config-update-topic + #Localization config egov.localization.host=https://dev.digit.org egov.localization.workDir.path=/localization/messages/v1 From 9d6333a97d17b7618d8b26cb4ec22ec42559957b Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Tue, 5 Mar 2024 16:44:25 +0530 Subject: [PATCH 05/53] [HLM-5129] Removed unused imports and cleaned up code --- .../main/java/digit/config/Configuration.java | 41 ----- .../java/digit/service/EnrichmentService.java | 10 +- .../service/PlanConfigurationService.java | 14 +- .../src/main/java/digit/util/IdgenUtil.java | 55 ------- .../java/digit/util/UrlShortenerUtil.java | 40 ----- .../src/main/java/digit/util/UserUtil.java | 140 ------------------ .../digit/web/controllers/PlanController.java | 12 +- .../src/main/java/digit/web/models/Plan.java | 6 - .../main/java/digit/web/models/Resource.java | 2 +- .../src/main/resources/application.properties | 2 +- 10 files changed, 14 insertions(+), 308 deletions(-) delete mode 100644 health-services/plan-service/src/main/java/digit/util/IdgenUtil.java delete mode 100644 health-services/plan-service/src/main/java/digit/util/UrlShortenerUtil.java delete mode 100644 health-services/plan-service/src/main/java/digit/util/UserUtil.java diff --git a/health-services/plan-service/src/main/java/digit/config/Configuration.java b/health-services/plan-service/src/main/java/digit/config/Configuration.java index b417d934c1b..4a6a484d4f1 100644 --- a/health-services/plan-service/src/main/java/digit/config/Configuration.java +++ b/health-services/plan-service/src/main/java/digit/config/Configuration.java @@ -22,32 +22,6 @@ @Getter public class Configuration { - - // User Config - @Value("${egov.user.host}") - private String userHost; - - @Value("${egov.user.context.path}") - private String userContextPath; - - @Value("${egov.user.create.path}") - private String userCreateEndpoint; - - @Value("${egov.user.search.path}") - private String userSearchEndpoint; - - @Value("${egov.user.update.path}") - private String userUpdateEndpoint; - - - //Idgen Config - @Value("${egov.idgen.host}") - private String idGenHost; - - @Value("${egov.idgen.path}") - private String idGenPath; - - //Workflow Config @Value("${egov.workflow.host}") private String wfHost; @@ -70,21 +44,6 @@ public class Configuration { private String mdmsEndPoint; - //HRMS - @Value("${egov.hrms.host}") - private String hrmsHost; - - @Value("${egov.hrms.search.endpoint}") - private String hrmsEndPoint; - - - //URLShortening - @Value("${egov.url.shortner.host}") - private String urlShortnerHost; - - @Value("${egov.url.shortner.endpoint}") - private String urlShortnerEndpoint; - //Persister Topic @Value("${plan.configuration.create.topic}") private String planConfigCreateTopic; diff --git a/health-services/plan-service/src/main/java/digit/service/EnrichmentService.java b/health-services/plan-service/src/main/java/digit/service/EnrichmentService.java index a0c4067908f..4f3a6680965 100644 --- a/health-services/plan-service/src/main/java/digit/service/EnrichmentService.java +++ b/health-services/plan-service/src/main/java/digit/service/EnrichmentService.java @@ -1,9 +1,7 @@ package digit.service; import digit.config.Configuration; -import digit.config.ServiceConstants; import digit.models.coremodels.AuditDetails; -import digit.util.IdgenUtil; import digit.web.models.Assumption; import digit.web.models.Operation; import digit.web.models.PlanConfiguration; @@ -17,13 +15,9 @@ @Service @Slf4j public class EnrichmentService { + private Configuration config; - private final IdgenUtil idgenUtil; - - private final Configuration config; - - public EnrichmentService(IdgenUtil idgenUtil, Configuration config) { - this.idgenUtil = idgenUtil; + public EnrichmentService(Configuration config) { this.config = config; } diff --git a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java index 21ed5e076f1..d4827d0e829 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java @@ -1,10 +1,10 @@ package digit.service; import digit.config.Configuration; +import digit.kafka.Producer; import digit.validators.PlanConfigurationValidator; import digit.web.models.PlanConfigurationRequest; -import org.egov.common.producer.Producer; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -13,17 +13,13 @@ @Slf4j public class PlanConfigurationService { - @Autowired - private final Producer producer; + private Producer producer; - @Autowired - private final EnrichmentService enrichmentService; + private EnrichmentService enrichmentService; - @Autowired - private final Configuration config; + private Configuration config; - @Autowired - private final PlanConfigurationValidator validator; + private PlanConfigurationValidator validator; public PlanConfigurationService(Producer producer, EnrichmentService enrichmentService, Configuration config, PlanConfigurationValidator validator) { this.producer = producer; diff --git a/health-services/plan-service/src/main/java/digit/util/IdgenUtil.java b/health-services/plan-service/src/main/java/digit/util/IdgenUtil.java deleted file mode 100644 index 5e4a18c199c..00000000000 --- a/health-services/plan-service/src/main/java/digit/util/IdgenUtil.java +++ /dev/null @@ -1,55 +0,0 @@ -package digit.util; - -import com.fasterxml.jackson.databind.ObjectMapper; -import digit.repository.ServiceRequestRepository; -import digit.config.Configuration; -//import digit.models.coremodels.IdGenerationRequest; -//import digit.models.coremodels.IdGenerationResponse; -//import digit.models.coremodels.IdRequest; -//import digit.models.coremodels.IdResponse; -import org.egov.common.contract.idgen.IdGenerationRequest; -import org.egov.common.contract.idgen.IdGenerationResponse; -import org.egov.common.contract.idgen.IdRequest; -import org.egov.common.contract.idgen.IdResponse; -import org.egov.common.contract.request.RequestInfo; -import org.egov.tracer.model.CustomException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import static digit.config.ServiceConstants.*; - -@Component -public class IdgenUtil { - - @Autowired - private ObjectMapper mapper; - - @Autowired - private ServiceRequestRepository restRepo; - - @Autowired - private Configuration configs; - - public List getIdList(RequestInfo requestInfo, String tenantId, String idName, String idformat, Integer count) { - List reqList = new ArrayList<>(); - for (int i = 0; i < count; i++) { - reqList.add(IdRequest.builder().idName(idName).format(idformat).tenantId(tenantId).build()); - } - - IdGenerationRequest request = IdGenerationRequest.builder().idRequests(reqList).requestInfo(requestInfo).build(); - StringBuilder uri = new StringBuilder(configs.getIdGenHost()).append(configs.getIdGenPath()); - IdGenerationResponse response = mapper.convertValue(restRepo.fetchResult(uri, request), IdGenerationResponse.class); - - List idResponses = response.getIdResponses(); - - if (CollectionUtils.isEmpty(idResponses)) - throw new CustomException(IDGEN_ERROR, NO_IDS_FOUND_ERROR); - - return idResponses.stream().map(IdResponse::getId).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/health-services/plan-service/src/main/java/digit/util/UrlShortenerUtil.java b/health-services/plan-service/src/main/java/digit/util/UrlShortenerUtil.java deleted file mode 100644 index 26c9c0048a1..00000000000 --- a/health-services/plan-service/src/main/java/digit/util/UrlShortenerUtil.java +++ /dev/null @@ -1,40 +0,0 @@ -package digit.util; - -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; -import java.util.HashMap; -import digit.config.Configuration; - -import static digit.config.ServiceConstants.*; - -@Slf4j -@Component -public class UrlShortenerUtil { - - @Autowired - private RestTemplate restTemplate; - - @Autowired - private Configuration configs; - - - public String getShortenedUrl(String url) { - - HashMap body = new HashMap<>(); - body.put(URL, url); - StringBuilder builder = new StringBuilder(configs.getUrlShortnerHost()); - builder.append(configs.getUrlShortnerEndpoint()); - String res = restTemplate.postForObject(builder.toString(), body, String.class); - - if (StringUtils.isEmpty(res)) { - log.error(URL_SHORTENING_ERROR_CODE, URL_SHORTENING_ERROR_MESSAGE + url); - ; - return url; - } else return res; - } - - -} \ No newline at end of file diff --git a/health-services/plan-service/src/main/java/digit/util/UserUtil.java b/health-services/plan-service/src/main/java/digit/util/UserUtil.java deleted file mode 100644 index 5a4c14e44a6..00000000000 --- a/health-services/plan-service/src/main/java/digit/util/UserUtil.java +++ /dev/null @@ -1,140 +0,0 @@ -package digit.util; - -import com.fasterxml.jackson.databind.ObjectMapper; -import digit.config.Configuration; - -import static digit.config.ServiceConstants.*; - -import digit.repository.ServiceRequestRepository; -import org.egov.common.contract.request.Role; -import org.egov.common.contract.request.User; -import org.egov.common.contract.user.UserDetailResponse; -import org.egov.common.contract.user.enums.UserType; -import org.egov.tracer.model.CustomException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; - -@Component -public class UserUtil { - - @Autowired - private ObjectMapper mapper; - - @Autowired - private ServiceRequestRepository serviceRequestRepository; - - @Autowired - private Configuration configs; - - - @Autowired - public UserUtil(ObjectMapper mapper, ServiceRequestRepository serviceRequestRepository) { - this.mapper = mapper; - this.serviceRequestRepository = serviceRequestRepository; - } - - /** - * Returns UserDetailResponse by calling user service with given uri and object - * - * @param userRequest Request object for user service - * @param uri The address of the endpoint - * @return Response from user service as parsed as userDetailResponse - */ - - public UserDetailResponse userCall(Object userRequest, StringBuilder uri) { - String dobFormat = null; - if (uri.toString().contains(configs.getUserSearchEndpoint()) || uri.toString().contains(configs.getUserUpdateEndpoint())) - dobFormat = DOB_FORMAT_Y_M_D; - else if (uri.toString().contains(configs.getUserCreateEndpoint())) - dobFormat = DOB_FORMAT_D_M_Y; - try { - LinkedHashMap responseMap = (LinkedHashMap) serviceRequestRepository.fetchResult(uri, userRequest); - parseResponse(responseMap, dobFormat); - UserDetailResponse userDetailResponse = mapper.convertValue(responseMap, UserDetailResponse.class); - return userDetailResponse; - } catch (IllegalArgumentException e) { - throw new CustomException(ILLEGAL_ARGUMENT_EXCEPTION_CODE, OBJECTMAPPER_UNABLE_TO_CONVERT); - } - } - - - /** - * Parses date formats to long for all users in responseMap - * - * @param responseMap LinkedHashMap got from user api response - */ - - public void parseResponse(LinkedHashMap responseMap, String dobFormat) { - List users = (List) responseMap.get(USER); - String format1 = DOB_FORMAT_D_M_Y_H_M_S; - if (users != null) { - users.forEach(map -> { - map.put(CREATED_DATE, dateTolong((String) map.get(CREATED_DATE), format1)); - if ((String) map.get(LAST_MODIFIED_DATE) != null) - map.put(LAST_MODIFIED_DATE, dateTolong((String) map.get(LAST_MODIFIED_DATE), format1)); - if ((String) map.get(DOB) != null) - map.put(DOB, dateTolong((String) map.get(DOB), dobFormat)); - if ((String) map.get(PWD_EXPIRY_DATE) != null) - map.put(PWD_EXPIRY_DATE, dateTolong((String) map.get(PWD_EXPIRY_DATE), format1)); - } - ); - } - } - - /** - * Converts date to long - * - * @param date date to be parsed - * @param format Format of the date - * @return Long value of date - */ - private Long dateTolong(String date, String format) { - SimpleDateFormat f = new SimpleDateFormat(format); - Date d = null; - try { - d = f.parse(date); - } catch (ParseException e) { - throw new CustomException(INVALID_DATE_FORMAT_CODE, INVALID_DATE_FORMAT_MESSAGE); - } - return d.getTime(); - } - - /** - * enriches the userInfo with statelevel tenantId and other fields - * The function creates user with username as mobile number. - * - * @param mobileNumber - * @param tenantId - * @param userInfo - */ - public void addUserDefaultFields(String mobileNumber, String tenantId, User userInfo, UserType userType) { - Role role = getCitizenRole(tenantId); - userInfo.setRoles(Collections.singletonList(role)); - userInfo.setType(String.valueOf(userType)); - userInfo.setUserName(mobileNumber); - userInfo.setTenantId(getStateLevelTenant(tenantId)); - } - - /** - * Returns role object for citizen - * - * @param tenantId - * @return - */ - private Role getCitizenRole(String tenantId) { - Role role = Role.builder().build(); - role.setCode(CITIZEN_UPPER); - role.setName(CITIZEN_LOWER); - role.setTenantId(getStateLevelTenant(tenantId)); - return role; - } - - public String getStateLevelTenant(String tenantId) { - return tenantId.split("\\.")[0]; - } - -} \ No newline at end of file diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java index 1428b306cad..9e42ff72449 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java @@ -3,9 +3,6 @@ import digit.web.models.*; import com.fasterxml.jackson.databind.ObjectMapper; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.media.Schema; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; @@ -17,26 +14,27 @@ @javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Controller +@RequestMapping("/plan") public class PlanController { - private final ObjectMapper objectMapper; + private ObjectMapper objectMapper; public PlanController(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } @RequestMapping(value = "/_create", method = RequestMethod.POST) - public ResponseEntity createPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanCreateRequest body) { + public ResponseEntity createPost(@Valid @RequestBody PlanCreateRequest body) { return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); } @RequestMapping(value = "/_search", method = RequestMethod.POST) - public ResponseEntity searchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanSearchRequest body) { + public ResponseEntity searchPost(@Valid @RequestBody PlanSearchRequest body) { return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); } @RequestMapping(value = "/_update", method = RequestMethod.POST) - public ResponseEntity updatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanEditRequest body) { + public ResponseEntity updatePost(@Valid @RequestBody PlanEditRequest body) { return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Plan.java b/health-services/plan-service/src/main/java/digit/web/models/Plan.java index 8f877d0f99a..5d38ad06bdd 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Plan.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Plan.java @@ -1,15 +1,9 @@ package digit.web.models; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import digit.web.models.Activity; -import digit.web.models.Target; -import io.swagger.v3.oas.annotations.media.Schema; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import org.springframework.core.io.Resource; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; import javax.validation.constraints.*; diff --git a/health-services/plan-service/src/main/java/digit/web/models/Resource.java b/health-services/plan-service/src/main/java/digit/web/models/Resource.java index 1d812abc757..a314954c1d7 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Resource.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Resource.java @@ -26,7 +26,7 @@ public class Resource { @JsonProperty("id") @Valid - private UUID id = null; + private String id = null; @JsonProperty("resourceType") private String resourceType = null; diff --git a/health-services/plan-service/src/main/resources/application.properties b/health-services/plan-service/src/main/resources/application.properties index da562f31a64..cab8b107f9a 100644 --- a/health-services/plan-service/src/main/resources/application.properties +++ b/health-services/plan-service/src/main/resources/application.properties @@ -1,5 +1,5 @@ server.port=8080 -server.servlet.context-path=/plan +server.servlet.context-path=/plan-service #MANAGEMENT ENDPOINT CONFIGURATION management.endpoints.web.base-path=/ From a770b28b03c0e3c928bf211d9c1ccc179adddf06 Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Tue, 5 Mar 2024 16:56:46 +0530 Subject: [PATCH 06/53] [HLM-5129] Cleaned up starter code --- .../main/java/digit/service/PlanService.java | 29 +++++++++++++++++++ .../digit/web/controllers/PlanController.java | 21 +++++++------- ...nSearchResponse.java => PlanResponse.java} | 4 +-- .../main/java/digit/web/models/Resource.java | 4 +-- 4 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 health-services/plan-service/src/main/java/digit/service/PlanService.java rename health-services/plan-service/src/main/java/digit/web/models/{PlanSearchResponse.java => PlanResponse.java} (90%) diff --git a/health-services/plan-service/src/main/java/digit/service/PlanService.java b/health-services/plan-service/src/main/java/digit/service/PlanService.java new file mode 100644 index 00000000000..ac0e29a19e7 --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/service/PlanService.java @@ -0,0 +1,29 @@ +package digit.service; + +import digit.web.models.PlanCreateRequest; +import digit.web.models.PlanResponse; +import org.egov.common.utils.ResponseInfoUtil; +import org.springframework.stereotype.Service; + +import java.util.Collections; + +@Service +public class PlanService { + + private ResponseInfoUtil responseInfoUtil; + + public PlanService(ResponseInfoUtil responseInfoUtil) { + this.responseInfoUtil = responseInfoUtil; + } + + public PlanResponse createPlan(PlanCreateRequest body) { + + // Validate plan create request + + + return PlanResponse.builder() + .responseInfo(responseInfoUtil.createResponseInfoFromRequestInfo(body.getRequestInfo(), Boolean.TRUE)) + .plan(Collections.singletonList(body.getPlan())) + .build(); + } +} diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java index 9e42ff72449..ed06cecb5e6 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java @@ -1,8 +1,8 @@ package digit.web.controllers; +import digit.service.PlanService; import digit.web.models.*; -import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; @@ -17,25 +17,26 @@ @RequestMapping("/plan") public class PlanController { - private ObjectMapper objectMapper; + private PlanService planService; - public PlanController(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; + public PlanController(PlanService planService) { + this.planService = planService; } @RequestMapping(value = "/_create", method = RequestMethod.POST) - public ResponseEntity createPost(@Valid @RequestBody PlanCreateRequest body) { - return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); + public ResponseEntity createPost(@Valid @RequestBody PlanCreateRequest body) { + PlanResponse planResponse = planService.createPlan(body); + return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanResponse()); } @RequestMapping(value = "/_search", method = RequestMethod.POST) - public ResponseEntity searchPost(@Valid @RequestBody PlanSearchRequest body) { - return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); + public ResponseEntity searchPost(@Valid @RequestBody PlanSearchRequest body) { + return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanResponse()); } @RequestMapping(value = "/_update", method = RequestMethod.POST) - public ResponseEntity updatePost(@Valid @RequestBody PlanEditRequest body) { - return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanSearchResponse()); + public ResponseEntity updatePost(@Valid @RequestBody PlanEditRequest body) { + return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanResponse()); } } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchResponse.java b/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java similarity index 90% rename from health-services/plan-service/src/main/java/digit/web/models/PlanSearchResponse.java rename to health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java index 4cabb5f4593..4af57c6308a 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchResponse.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java @@ -20,7 +20,7 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PlanSearchResponse { +public class PlanResponse { @JsonProperty("ResponseInfo") @Valid private ResponseInfo responseInfo = null; @@ -30,7 +30,7 @@ public class PlanSearchResponse { private List plan = null; - public PlanSearchResponse addPlanItem(Plan planItem) { + public PlanResponse addPlanItem(Plan planItem) { if (this.plan == null) { this.plan = new ArrayList<>(); } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Resource.java b/health-services/plan-service/src/main/java/digit/web/models/Resource.java index a314954c1d7..6ca09cb6538 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Resource.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Resource.java @@ -24,16 +24,14 @@ @NoArgsConstructor @Builder public class Resource { + @JsonProperty("id") - @Valid private String id = null; @JsonProperty("resourceType") private String resourceType = null; @JsonProperty("estimatedNumber") - @Valid private BigDecimal estimatedNumber = null; - } From cabe7dc7e9c2a6c200c4f589e9d44718c03857b0 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 5 Mar 2024 17:35:36 +0530 Subject: [PATCH 07/53] HLM-5117 Removing unnecessary integrations --- health-services/plan-service/pom.xml | 6 ++-- .../java/digit/config/ServiceConstants.java | 3 +- .../service/PlanConfigurationService.java | 6 ++-- .../{ => enrichment}/EnrichmentService.java | 30 ++++++++++++++++++- .../PlanConfigurationValidator.java | 2 +- .../java/digit/web/models/Assumption.java | 3 +- .../digit/web/models/PlanConfiguration.java | 7 ----- 7 files changed, 39 insertions(+), 18 deletions(-) rename health-services/plan-service/src/main/java/digit/service/{ => enrichment}/EnrichmentService.java (56%) rename health-services/plan-service/src/main/java/digit/{validators => service/validator}/PlanConfigurationValidator.java (91%) diff --git a/health-services/plan-service/pom.xml b/health-services/plan-service/pom.xml index 9d6f849d021..eec409738ef 100644 --- a/health-services/plan-service/pom.xml +++ b/health-services/plan-service/pom.xml @@ -117,9 +117,9 @@ test - org.egov.common - health-services-common - 1.0.15-SNAPSHOT + org.egov.services + digit-models + 1.0.0-SNAPSHOT compile diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index 6b0c4a6f9ab..5ecae1f4195 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -46,5 +46,6 @@ public class ServiceConstants { public static final String TENANTID = "?tenantId="; public static final String BUSINESS_SERVICES = "&businessServices="; - + public static final String USERINFO_MISSING_CODE = "USERINFO_MISSING"; + public static final String USERINFO_MISSING_MESSAGE = "UserInfo is missing in Request Info "; } diff --git a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java index d4827d0e829..dfd6006b3d4 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java @@ -2,11 +2,11 @@ import digit.config.Configuration; import digit.kafka.Producer; -import digit.validators.PlanConfigurationValidator; +import digit.service.enrichment.EnrichmentService; +import digit.service.validator.PlanConfigurationValidator; import digit.web.models.PlanConfigurationRequest; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service @@ -32,6 +32,6 @@ public PlanConfigurationRequest create(PlanConfigurationRequest request) { enrichmentService.enrichCreate(request); validator.validateCreate(request); producer.push(config.getPlanConfigCreateTopic() ,request); - return new PlanConfigurationRequest(); + return request; } } \ No newline at end of file diff --git a/health-services/plan-service/src/main/java/digit/service/EnrichmentService.java b/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java similarity index 56% rename from health-services/plan-service/src/main/java/digit/service/EnrichmentService.java rename to health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java index 4f3a6680965..11f4dc01a7b 100644 --- a/health-services/plan-service/src/main/java/digit/service/EnrichmentService.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java @@ -1,16 +1,22 @@ -package digit.service; +package digit.service.enrichment; import digit.config.Configuration; import digit.models.coremodels.AuditDetails; import digit.web.models.Assumption; +import digit.web.models.File; import digit.web.models.Operation; import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; +import digit.web.models.ResourceMapping; import java.util.List; import java.util.UUID; import lombok.extern.slf4j.Slf4j; +import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Service; +import static digit.config.ServiceConstants.USERINFO_MISSING_CODE; +import static digit.config.ServiceConstants.USERINFO_MISSING_MESSAGE; + @Service @Slf4j @@ -23,7 +29,10 @@ public EnrichmentService(Configuration config) { public void enrichCreate(PlanConfigurationRequest request) { enrichPlanConfiguration(request.getPlanConfiguration()); + if(request.getRequestInfo().getUserInfo() == null) + throw new CustomException(USERINFO_MISSING_CODE, USERINFO_MISSING_MESSAGE); + enrichAuditDetails(request.getPlanConfiguration(), request.getRequestInfo().getUserInfo().getUuid(), Boolean.TRUE); } public PlanConfiguration enrichPlanConfiguration(PlanConfiguration planConfiguration) { @@ -47,6 +56,25 @@ public PlanConfiguration enrichPlanConfiguration(PlanConfiguration planConfigura return planConfiguration; } + public void enrichAuditDetails(PlanConfiguration planConfiguration, String by, Boolean isCreate) { + Long time = System.currentTimeMillis(); + for (Operation operation : planConfiguration.getOperations()) { + operation.setAuditDetails(getAuditDetails(by, operation.getAuditDetails(), isCreate)); + } + + for (Assumption assumption : planConfiguration.getAssumptions()) { + assumption.setAuditDetails(getAuditDetails(by, assumption.getAuditDetails(), isCreate)); + } + + for (File file : planConfiguration.getFiles()) { + file.setAuditDetails(getAuditDetails(by, file.getAuditDetails(), isCreate)); + } + + for (ResourceMapping resourceMapping : planConfiguration.getResourceMapping()) { + resourceMapping.setAuditDetails(getAuditDetails(by, resourceMapping.getAuditDetails(), isCreate)); + } + } + public AuditDetails getAuditDetails(String by, AuditDetails auditDetails, Boolean isCreate) { Long time = System.currentTimeMillis(); if (isCreate) diff --git a/health-services/plan-service/src/main/java/digit/validators/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java similarity index 91% rename from health-services/plan-service/src/main/java/digit/validators/PlanConfigurationValidator.java rename to health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index 448d9936ebd..56d097c68b6 100644 --- a/health-services/plan-service/src/main/java/digit/validators/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -1,4 +1,4 @@ -package digit.validators; +package digit.service.validator; import digit.web.models.PlanConfigurationRequest; import lombok.extern.slf4j.Slf4j; diff --git a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java index 537d92d1671..463c296e61b 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java @@ -3,8 +3,7 @@ import digit.models.coremodels.AuditDetails; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import io.swagger.v3.oas.annotations.media.Schema; + import java.math.BigDecimal; import java.util.UUID; import org.springframework.validation.annotation.Validated; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java index be314638555..276ee602a4f 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java @@ -1,14 +1,7 @@ package digit.web.models; import digit.models.coremodels.AuditDetails; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import digit.web.models.Assumption; -import digit.web.models.Operation; -import digit.web.models.ResourceMapping; -import io.swagger.v3.oas.annotations.media.Schema; -import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.UUID; From c69a505e39f9e001df205458b234b22afdd53946 Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Wed, 6 Mar 2024 11:56:06 +0530 Subject: [PATCH 08/53] [HLM-5129] Made changes to plan POJOs and db schema files --- .../main/java/digit/service/PlanEnricher.java | 14 +++ .../main/java/digit/service/PlanService.java | 14 ++- .../java/digit/service/PlanValidator.java | 112 ++++++++++++++++++ .../main/java/digit/web/models/Activity.java | 3 + .../src/main/java/digit/web/models/Plan.java | 29 +---- .../java/digit/web/models/PlanResponse.java | 10 +- .../main/java/digit/web/models/Resource.java | 3 + .../main/java/digit/web/models/Target.java | 2 + .../main/V20240305113047__plan_create_ddl.sql | 12 +- 9 files changed, 155 insertions(+), 44 deletions(-) create mode 100644 health-services/plan-service/src/main/java/digit/service/PlanEnricher.java create mode 100644 health-services/plan-service/src/main/java/digit/service/PlanValidator.java diff --git a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java new file mode 100644 index 00000000000..3bacba9d5cb --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java @@ -0,0 +1,14 @@ +package digit.service; + +import digit.web.models.PlanCreateRequest; +import org.egov.common.utils.UUIDEnrichmentUtil; +import org.springframework.stereotype.Component; + +@Component +public class PlanEnricher { + + + public void enrichPlanCreate(PlanCreateRequest body) { + UUIDEnrichmentUtil.enrichRandomUuid(body.getPlan(), "id"); + } +} diff --git a/health-services/plan-service/src/main/java/digit/service/PlanService.java b/health-services/plan-service/src/main/java/digit/service/PlanService.java index ac0e29a19e7..7552b738ce8 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanService.java @@ -10,19 +10,25 @@ @Service public class PlanService { - private ResponseInfoUtil responseInfoUtil; + private PlanValidator planValidator; - public PlanService(ResponseInfoUtil responseInfoUtil) { - this.responseInfoUtil = responseInfoUtil; + private PlanEnricher planEnricher; + + public PlanService(PlanValidator planValidator, PlanEnricher planEnricher) { + this.planValidator = planValidator; + this.planEnricher = planEnricher; } public PlanResponse createPlan(PlanCreateRequest body) { // Validate plan create request + planValidator.validatePlanCreate(body); + // Enrich plan create request + planEnricher.enrichPlanCreate(body); return PlanResponse.builder() - .responseInfo(responseInfoUtil.createResponseInfoFromRequestInfo(body.getRequestInfo(), Boolean.TRUE)) + .responseInfo(ResponseInfoUtil.createResponseInfoFromRequestInfo(body.getRequestInfo(), Boolean.TRUE)) .plan(Collections.singletonList(body.getPlan())) .build(); } diff --git a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java new file mode 100644 index 00000000000..687ed4034cd --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java @@ -0,0 +1,112 @@ +package digit.service; + +import digit.web.models.Activity; +import digit.web.models.PlanCreateRequest; +import org.egov.tracer.model.CustomException; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; + +import java.util.Set; +import java.util.stream.Collectors; + +@Component +public class PlanValidator { + + public void validatePlanCreate(PlanCreateRequest request) { + + // Validate execution plan existence + validateExecutionPlanExistence(request); + + // Validate activities + validateActivities(request); + + // Validate plan configuration existence + validatePlanConfigurationExistence(request); + + // Validate resources + validateResources(request); + + // Validate resource-activity linkage + validateResourceActivityLinkage(request); + + // Validate target-activity linkage + validateTargetActivityLinkage(request); + + } + + private void validateExecutionPlanExistence(PlanCreateRequest request) { + } + + private void validateActivities(PlanCreateRequest request) { + // If execution plan id is not provided, providing activities is mandatory + if(ObjectUtils.isEmpty(request.getPlan().getExecutionPlanId()) + && CollectionUtils.isEmpty(request.getPlan().getActivities())) { + throw new CustomException("PLAN_ACTIVITIES_MANDATORY", "Activities are mandatory if execution plan id is not provided"); + } + + // If execution plan id is provided, providing activities is not allowed + if(!ObjectUtils.isEmpty(request.getPlan().getExecutionPlanId()) + && !CollectionUtils.isEmpty(request.getPlan().getActivities())) { + throw new CustomException("PLAN_ACTIVITIES_NOT_ALLOWED", "Activities are not allowed if execution plan id is provided"); + } + + // Validate activity dates + if(!CollectionUtils.isEmpty(request.getPlan().getActivities())) { + request.getPlan().getActivities().forEach(activity -> { + if(activity.getPlannedEndDate() < activity.getPlannedStartDate()) + throw new CustomException("INVALID_ACTIVITY_DATES", "Planned end date cannot be before planned start date"); + }); + } + } + + private void validatePlanConfigurationExistence(PlanCreateRequest request) { + + } + + private void validateResources(PlanCreateRequest request) { + // If plan configuration id is not provided, providing resources is mandatory + if(ObjectUtils.isEmpty(request.getPlan().getPlanConfigurationId()) + && CollectionUtils.isEmpty(request.getPlan().getResources())) { + throw new CustomException("PLAN_RESOURCES_MANDATORY", "Resources are mandatory if plan configuration id is not provided"); + } + + // If plan configuration id is provided, providing resources is not allowed + if(!ObjectUtils.isEmpty(request.getPlan().getPlanConfigurationId()) + && !CollectionUtils.isEmpty(request.getPlan().getResources())) { + throw new CustomException("PLAN_RESOURCES_NOT_ALLOWED", "Resources are not allowed if plan configuration id is provided"); + } + + // Validate resource type existence + if(!CollectionUtils.isEmpty(request.getPlan().getResources())) { + request.getPlan().getResources().forEach(resource -> { + // Validate resource type existence + }); + } + } + + private void validateResourceActivityLinkage(PlanCreateRequest request) { + if(!CollectionUtils.isEmpty(request.getPlan().getActivities())) { + Set activityCodes = request.getPlan().getActivities().stream() + .map(Activity::getCode) + .collect(Collectors.toSet()); + request.getPlan().getResources().forEach(resource -> { + if(!activityCodes.contains(resource.getActivityCode())) + throw new CustomException("INVALID_RESOURCE_ACTIVITY_LINKAGE", "Resource-Activity linkage is invalid"); + }); + } + } + + private void validateTargetActivityLinkage(PlanCreateRequest request) { + if(!CollectionUtils.isEmpty(request.getPlan().getActivities())) { + Set activityCodes = request.getPlan().getActivities().stream() + .map(Activity::getCode) + .collect(Collectors.toSet()); + request.getPlan().getTargets().forEach(target -> { + if(!activityCodes.contains(target.getActivityCode())) + throw new CustomException("INVALID_TARGET_ACTIVITY_LINKAGE", "Target-Activity linkage is invalid"); + }); + } + } + +} diff --git a/health-services/plan-service/src/main/java/digit/web/models/Activity.java b/health-services/plan-service/src/main/java/digit/web/models/Activity.java index 64d920a0f88..9923f7a16f3 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Activity.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Activity.java @@ -31,6 +31,9 @@ public class Activity { @JsonProperty("tenantId") private String tenantId = null; + @JsonProperty("code") + private String code = null; + @JsonProperty("description") private String description = null; diff --git a/health-services/plan-service/src/main/java/digit/web/models/Plan.java b/health-services/plan-service/src/main/java/digit/web/models/Plan.java index 5d38ad06bdd..7f3cf10810f 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Plan.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Plan.java @@ -22,9 +22,9 @@ @NoArgsConstructor @Builder public class Plan { + @JsonProperty("id") - @Valid - private UUID id = null; + private String id = null; @JsonProperty("tenantId") private String tenantId = null; @@ -54,29 +54,4 @@ public class Plan { @Valid private List targets = null; - - public Plan addActivitiesItem(Activity activitiesItem) { - if (this.activities == null) { - this.activities = new ArrayList<>(); - } - this.activities.add(activitiesItem); - return this; - } - - public Plan addResourcesItem(Resource resourcesItem) { - if (this.resources == null) { - this.resources = new ArrayList<>(); - } - this.resources.add(resourcesItem); - return this; - } - - public Plan addTargetsItem(Target targetsItem) { - if (this.targets == null) { - this.targets = new ArrayList<>(); - } - this.targets.add(targetsItem); - return this; - } - } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java b/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java index 4af57c6308a..09a9e7b499f 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java @@ -21,6 +21,7 @@ @NoArgsConstructor @Builder public class PlanResponse { + @JsonProperty("ResponseInfo") @Valid private ResponseInfo responseInfo = null; @@ -29,13 +30,4 @@ public class PlanResponse { @Valid private List plan = null; - - public PlanResponse addPlanItem(Plan planItem) { - if (this.plan == null) { - this.plan = new ArrayList<>(); - } - this.plan.add(planItem); - return this; - } - } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Resource.java b/health-services/plan-service/src/main/java/digit/web/models/Resource.java index 6ca09cb6538..22cb20afb95 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Resource.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Resource.java @@ -34,4 +34,7 @@ public class Resource { @JsonProperty("estimatedNumber") private BigDecimal estimatedNumber = null; + @JsonProperty("activityCode") + private String activityCode = null; + } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Target.java b/health-services/plan-service/src/main/java/digit/web/models/Target.java index f153ecbe190..b3490cbff56 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Target.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Target.java @@ -37,5 +37,7 @@ public class Target { @JsonProperty("metricDetail") private Object metricDetail = null; + @JsonProperty("activityCode") + private String activityCode = null; } diff --git a/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql b/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql index fa244addcb1..e19b8a66bf2 100644 --- a/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql +++ b/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql @@ -15,6 +15,7 @@ CREATE TABLE plan ( CREATE TABLE plan_activity ( id varchar(64), tenant_id varchar(64), + code varchar(128), description varchar(2048), planned_start_date bigint, planned_end_date bigint, @@ -31,13 +32,13 @@ CREATE TABLE plan_activity ( CREATE TABLE plan_activity_dependency ( id varchar(64), activity_id varchar(64), - precursor_activity_id varchar(64), + precursor_activity_code varchar(64), created_by varchar(64), created_time bigint, last_modified_by varchar(64), last_modified_time bigint, CONSTRAINT uk_plan_activity_dependency_id PRIMARY KEY (id), - FOREIGN KEY (activity_id) REFERENCES plan(id) + FOREIGN KEY (activity_id) REFERENCES plan_activity(id) ); CREATE TABLE plan_activity_condition ( @@ -51,7 +52,7 @@ CREATE TABLE plan_activity_condition ( last_modified_by varchar(64), last_modified_time bigint, CONSTRAINT uk_plan_activity_condition_id PRIMARY KEY (id), - FOREIGN KEY (activity_id) REFERENCES plan(id) + FOREIGN KEY (activity_id) REFERENCES plan_activity(id) ); CREATE TABLE plan_resource ( @@ -59,11 +60,13 @@ CREATE TABLE plan_resource ( resource_type varchar(256), estimated_number numeric(12,2), plan_id varchar(64), + activity_code varchar(128), created_by varchar(64), created_time bigint, last_modified_by varchar(64), last_modified_time bigint, - CONSTRAINT uk_plan_resource_id PRIMARY KEY (id) + CONSTRAINT uk_plan_resource_id PRIMARY KEY (id), + FOREIGN KEY (plan_id) REFERENCES plan(id) ); CREATE TABLE plan_target ( @@ -73,6 +76,7 @@ CREATE TABLE plan_target ( metric_comparator varchar(64), metric_unit varchar(128), plan_id varchar(64), + activity_code varchar(128), created_by varchar(64), created_time bigint, last_modified_by varchar(64), From 5d555f1c5b3662bb17943fe712a753931d24c2d8 Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Wed, 6 Mar 2024 16:49:22 +0530 Subject: [PATCH 09/53] Code cleanup --- health-services/plan-service/pom.xml | 38 +++++--------- .../main/java/digit/config/Configuration.java | 1 - .../java/digit/config/MainConfiguration.java | 6 +-- .../java/digit/service/PlanValidator.java | 38 ++++++++++++++ .../web/controllers/PlanConfigController.java | 1 - .../digit/web/controllers/PlanController.java | 5 +- .../main/java/digit/web/models/Activity.java | 38 +++----------- .../java/digit/web/models/Assumption.java | 1 - .../main/java/digit/web/models/Condition.java | 1 - .../src/main/java/digit/web/models/Error.java | 51 ------------------- .../main/java/digit/web/models/ErrorRes.java | 45 ---------------- .../src/main/java/digit/web/models/File.java | 1 - .../main/java/digit/web/models/Operation.java | 1 - .../src/main/java/digit/web/models/Plan.java | 3 -- .../digit/web/models/PlanConfiguration.java | 1 - .../web/models/PlanConfigurationRequest.java | 1 - .../web/models/PlanConfigurationResponse.java | 1 - .../PlanConfigurationSearchCriteria.java | 1 - .../PlanConfigurationSearchRequest.java | 1 - .../digit/web/models/PlanCreateRequest.java | 1 - .../digit/web/models/PlanEditRequest.java | 1 - .../java/digit/web/models/PlanResponse.java | 1 - .../digit/web/models/PlanSearchCriteria.java | 1 - .../digit/web/models/PlanSearchRequest.java | 1 - .../main/java/digit/web/models/Resource.java | 1 - .../digit/web/models/ResourceMapping.java | 1 - .../main/java/digit/web/models/Target.java | 1 - 27 files changed, 63 insertions(+), 180 deletions(-) delete mode 100644 health-services/plan-service/src/main/java/digit/web/models/Error.java delete mode 100644 health-services/plan-service/src/main/java/digit/web/models/ErrorRes.java diff --git a/health-services/plan-service/pom.xml b/health-services/plan-service/pom.xml index eec409738ef..5cdd3f77b6e 100644 --- a/health-services/plan-service/pom.xml +++ b/health-services/plan-service/pom.xml @@ -40,6 +40,10 @@ org.springframework.boot spring-boot-starter-jdbc + + org.hibernate.validator + hibernate-validator + org.flywaydb flyway-core @@ -55,7 +59,10 @@ spring-boot-starter-test test - + + org.springframework.boot + spring-boot-starter-validation + io.swagger swagger-core @@ -67,17 +74,16 @@ 2.2.8 - org.egov.services tracer 2.9.0-SNAPSHOT - - - - - + + org.egov.services + digit-models + 1.0.0-SNAPSHOT + org.egov mdms-client @@ -94,18 +100,6 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 - - - javax.annotation - javax.annotation-api - 1.3.2 - - - javax.servlet - javax.servlet-api - 4.0.1 - provided - junit junit @@ -116,12 +110,6 @@ junit test - - org.egov.services - digit-models - 1.0.0-SNAPSHOT - compile - diff --git a/health-services/plan-service/src/main/java/digit/config/Configuration.java b/health-services/plan-service/src/main/java/digit/config/Configuration.java index 4a6a484d4f1..313ada777c0 100644 --- a/health-services/plan-service/src/main/java/digit/config/Configuration.java +++ b/health-services/plan-service/src/main/java/digit/config/Configuration.java @@ -10,7 +10,6 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; import java.util.TimeZone; @Component diff --git a/health-services/plan-service/src/main/java/digit/config/MainConfiguration.java b/health-services/plan-service/src/main/java/digit/config/MainConfiguration.java index 60b7660e94c..a0f8e0ee2af 100644 --- a/health-services/plan-service/src/main/java/digit/config/MainConfiguration.java +++ b/health-services/plan-service/src/main/java/digit/config/MainConfiguration.java @@ -1,5 +1,6 @@ package digit.config; +import jakarta.annotation.PostConstruct; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.beans.factory.annotation.Autowired; @@ -7,9 +8,8 @@ import org.springframework.http.MediaType; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import java.util.TimeZone; -import javax.annotation.PostConstruct; - import com.fasterxml.jackson.databind.DeserializationFeature; - import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import org.egov.tracer.config.TracerConfiguration; diff --git a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java index 687ed4034cd..86d1ae5103a 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java @@ -7,6 +7,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -33,6 +34,43 @@ public void validatePlanCreate(PlanCreateRequest request) { // Validate target-activity linkage validateTargetActivityLinkage(request); + // Validate dependencies + validateActivityDependencies(request); + + } + + private void validateActivityDependencies(PlanCreateRequest request) { + // Check if dependent activity codes are valid + validateDependentActivityCodes(request); + + // Check if dependent activities form a cycle + checkForCycleInActivityDependencies(request); + } + + private void checkForCycleInActivityDependencies(PlanCreateRequest request) { + Map> activityCodeVsDependenciesMap = request.getPlan().getActivities().stream() + .collect(Collectors.toMap(Activity::getCode, Activity::getDependencies)); + + activityCodeVsDependenciesMap.keySet().forEach(activityCode -> { + activityCodeVsDependenciesMap.get(activityCode).forEach(dependency -> { + if(activityCodeVsDependenciesMap.get(dependency).contains(activityCode)) + throw new CustomException("CYCLIC_ACTIVITY_DEPENDENCY", "Cyclic activity dependency found"); + }); + }); + } + + private void validateDependentActivityCodes(PlanCreateRequest request) { + request.getPlan().getActivities().forEach(activity -> { + if(!CollectionUtils.isEmpty(activity.getDependencies())) { + Set activityCodes = request.getPlan().getActivities().stream() + .map(Activity::getCode) + .collect(Collectors.toSet()); + activity.getDependencies().forEach(dependency -> { + if(!activityCodes.contains(dependency)) + throw new CustomException("INVALID_ACTIVITY_DEPENDENCY", "Activity dependency is invalid"); + }); + } + }); } private void validateExecutionPlanExistence(PlanCreateRequest request) { diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java index ce6bfdf0f36..16798719446 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java @@ -20,7 +20,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import java.util.*; -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Controller public class PlanConfigController { diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java index ed06cecb5e6..12b266628d9 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java @@ -3,6 +3,7 @@ import digit.service.PlanService; import digit.web.models.*; +import jakarta.validation.Valid; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; @@ -10,9 +11,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMapping; -import javax.validation.Valid; -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Controller @RequestMapping("/plan") public class PlanController { @@ -26,7 +25,7 @@ public PlanController(PlanService planService) { @RequestMapping(value = "/_create", method = RequestMethod.POST) public ResponseEntity createPost(@Valid @RequestBody PlanCreateRequest body) { PlanResponse planResponse = planService.createPlan(body); - return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanResponse()); + return ResponseEntity.status(HttpStatus.ACCEPTED).body(planResponse); } @RequestMapping(value = "/_search", method = RequestMethod.POST) diff --git a/health-services/plan-service/src/main/java/digit/web/models/Activity.java b/health-services/plan-service/src/main/java/digit/web/models/Activity.java index 9923f7a16f3..300766b28dd 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Activity.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Activity.java @@ -1,15 +1,13 @@ package digit.web.models; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import digit.web.models.Condition; -import io.swagger.v3.oas.annotations.media.Schema; -import java.util.ArrayList; import java.util.List; +import java.util.Set; + import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; + import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; @@ -19,7 +17,6 @@ * Activity */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor @@ -28,10 +25,8 @@ public class Activity { @JsonProperty("id") private String id = null; - @JsonProperty("tenantId") - private String tenantId = null; - @JsonProperty("code") + @NotNull private String code = null; @JsonProperty("description") @@ -44,29 +39,10 @@ public class Activity { private Long plannedEndDate = null; @JsonProperty("dependencies") - private List dependencies = null; - - @JsonProperty("resourceId") - private String resourceId = null; + private Set dependencies = null; @JsonProperty("conditions") @Valid private List conditions = null; - public Activity addDependenciesItem(String dependenciesItem) { - if (this.dependencies == null) { - this.dependencies = new ArrayList<>(); - } - this.dependencies.add(dependenciesItem); - return this; - } - - public Activity addConditionsItem(Condition conditionsItem) { - if (this.conditions == null) { - this.conditions = new ArrayList<>(); - } - this.conditions.add(conditionsItem); - return this; - } - } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java index 463c296e61b..57885e85349 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java @@ -18,7 +18,6 @@ * Assumption */ @Validated -//@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/Condition.java b/health-services/plan-service/src/main/java/digit/web/models/Condition.java index 500cac71ca1..ba26b6224d4 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Condition.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Condition.java @@ -16,7 +16,6 @@ * Condition */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/Error.java b/health-services/plan-service/src/main/java/digit/web/models/Error.java deleted file mode 100644 index fca85a2f76f..00000000000 --- a/health-services/plan-service/src/main/java/digit/web/models/Error.java +++ /dev/null @@ -1,51 +0,0 @@ -package digit.web.models; - -import java.util.Objects; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import io.swagger.v3.oas.annotations.media.Schema; -import java.util.ArrayList; -import java.util.List; -import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; -import lombok.Data; -import lombok.Builder; - -/** - * Error object will be returned as a part of reponse body in conjunction with ResponseInfo as part of ErrorResponse whenever the request processing status in the ResponseInfo is FAILED. HTTP return in this scenario will usually be HTTP 400. - */ -@Schema(description = "Error object will be returned as a part of reponse body in conjunction with ResponseInfo as part of ErrorResponse whenever the request processing status in the ResponseInfo is FAILED. HTTP return in this scenario will usually be HTTP 400.") -@Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") -@Data -@AllArgsConstructor -@NoArgsConstructor -@Builder -public class Error { - @JsonProperty("code") - @NotNull - private String code = null; - - @JsonProperty("message") - @NotNull - private String message = null; - - @JsonProperty("description") - private String description = null; - - @JsonProperty("params") - private List params = null; - - - public Error addParamsItem(String paramsItem) { - if (this.params == null) { - this.params = new ArrayList<>(); - } - this.params.add(paramsItem); - return this; - } - -} diff --git a/health-services/plan-service/src/main/java/digit/web/models/ErrorRes.java b/health-services/plan-service/src/main/java/digit/web/models/ErrorRes.java deleted file mode 100644 index bde3acbc471..00000000000 --- a/health-services/plan-service/src/main/java/digit/web/models/ErrorRes.java +++ /dev/null @@ -1,45 +0,0 @@ -package digit.web.models; - -import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import java.util.ArrayList; -import java.util.List; -import org.egov.common.contract.response.ResponseInfo; -import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; -import lombok.Data; -import lombok.Builder; - -/** - * All APIs will return ErrorRes in case of failure which will carry ResponseInfo as metadata and Error object as actual representation of error. In case of bulk apis, some apis may chose to return the array of Error objects to indicate individual failure. - */ -@Schema(description = "All APIs will return ErrorRes in case of failure which will carry ResponseInfo as metadata and Error object as actual representation of error. In case of bulk apis, some apis may chose to return the array of Error objects to indicate individual failure.") -@Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") -@Data -@AllArgsConstructor -@NoArgsConstructor -@Builder -public class ErrorRes { - @JsonProperty("ResponseInfo") - @NotNull - @Valid - private ResponseInfo responseInfo = null; - - @JsonProperty("Errors") - @Valid - private List errors = null; - - - public ErrorRes addErrorsItem(Error errorsItem) { - if (this.errors == null) { - this.errors = new ArrayList<>(); - } - this.errors.add(errorsItem); - return this; - } - -} diff --git a/health-services/plan-service/src/main/java/digit/web/models/File.java b/health-services/plan-service/src/main/java/digit/web/models/File.java index f03d1c68c3b..6067c56a3ba 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/File.java +++ b/health-services/plan-service/src/main/java/digit/web/models/File.java @@ -19,7 +19,6 @@ * File */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/Operation.java b/health-services/plan-service/src/main/java/digit/web/models/Operation.java index 13d8a965def..6518daba2a5 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Operation.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Operation.java @@ -19,7 +19,6 @@ * Operation */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/Plan.java b/health-services/plan-service/src/main/java/digit/web/models/Plan.java index 7f3cf10810f..1f3f6db4418 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Plan.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Plan.java @@ -1,9 +1,7 @@ package digit.web.models; import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.ArrayList; import java.util.List; -import java.util.UUID; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; import javax.validation.constraints.*; @@ -16,7 +14,6 @@ * Plan */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java index 276ee602a4f..d3637ba09d2 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java @@ -17,7 +17,6 @@ * PlanConfiguration */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java index 46319d45367..1f428231b59 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java @@ -14,7 +14,6 @@ * PlanConfigurationRequest */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java index b6331b2f31d..1ac7464b8f2 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java @@ -15,7 +15,6 @@ * PlanConfigurationResponse */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java index 6e580e85f0a..da979d641c8 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java @@ -16,7 +16,6 @@ * PlanConfigurationSearchCriteria */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java index 114f10e1d9e..6f9aecc4476 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java @@ -13,7 +13,6 @@ * PlanConfigurationSearchRequest */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java index 72d2654fa93..8b55bd1b722 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java @@ -13,7 +13,6 @@ * PlanCreateRequest */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java index 28e985ef587..9e0ec4f1d1c 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java @@ -13,7 +13,6 @@ * PlanEditRequest */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java b/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java index 09a9e7b499f..61b8f2b652f 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java @@ -15,7 +15,6 @@ * PlanSearchResponse */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java index 1cef6760225..cf5a39b486a 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java @@ -16,7 +16,6 @@ * PlanSearchCriteria */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java index fee09f5bf00..4e231f63bef 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java @@ -13,7 +13,6 @@ * PlanSearchRequest */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/Resource.java b/health-services/plan-service/src/main/java/digit/web/models/Resource.java index 22cb20afb95..e29a308e373 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Resource.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Resource.java @@ -18,7 +18,6 @@ * Resource */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java index 56859baa4b2..ecfaad17e63 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java +++ b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java @@ -17,7 +17,6 @@ * ResourceMapping */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/health-services/plan-service/src/main/java/digit/web/models/Target.java b/health-services/plan-service/src/main/java/digit/web/models/Target.java index b3490cbff56..c4124b8d18b 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Target.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Target.java @@ -17,7 +17,6 @@ * Target */ @Validated -@javax.annotation.Generated(value = "org.egov.codegen.SpringBootCodegen", date = "2024-03-04T09:55:29.782094600+05:30[Asia/Calcutta]") @Data @AllArgsConstructor @NoArgsConstructor From d40e2628fb9ecbc85e419198787615e20ebec0aa Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 6 Mar 2024 17:46:58 +0530 Subject: [PATCH 10/53] HLM-5184 adding validations --- .../java/digit/config/ServiceConstants.java | 12 ++++ .../PlanConfigurationRepository.java | 14 ++++ .../impl/PlanConfigurationRepositoryImpl.java | 37 +++++++++++ .../service/PlanConfigurationService.java | 10 ++- .../validator/PlanConfigurationValidator.java | 65 ++++++++++++++++++- .../src/main/java/digit/util/MdmsUtil.java | 2 - .../validator/project/ProjectValidator.java | 1 - 7 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 health-services/plan-service/src/main/java/digit/repository/PlanConfigurationRepository.java create mode 100644 health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index 5ecae1f4195..83ec4d5ced3 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -48,4 +48,16 @@ public class ServiceConstants { public static final String USERINFO_MISSING_CODE = "USERINFO_MISSING"; public static final String USERINFO_MISSING_MESSAGE = "UserInfo is missing in Request Info "; + + public static final String ASSUMPTION_VALUE_NOT_FOUND_CODE = "ASSUMPTION_VALUE_NOT_FOUND"; + public static final String ASSUMPTION_VALUE_NOT_FOUND_MESSAGE = "Operation's Assumption value not found in assumptions list "; + + public static final String ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_CODE = "ASSUMPTION_KEY_NOT_FOUND_IN_MDMS"; + public static final String ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_MESSAGE = "Assumption Key is not present in MDMS"; + + public static final String MDMS_PLAN_ASSUMPTION_MODULE_NAME = ""; + + public static final String MDMS_MASTER_ASSUMPTION = ""; + + } diff --git a/health-services/plan-service/src/main/java/digit/repository/PlanConfigurationRepository.java b/health-services/plan-service/src/main/java/digit/repository/PlanConfigurationRepository.java new file mode 100644 index 00000000000..658c91afce3 --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/repository/PlanConfigurationRepository.java @@ -0,0 +1,14 @@ +package digit.repository; + + +import digit.web.models.PlanConfigurationRequest; +import org.springframework.stereotype.Repository; + +@Repository +public interface PlanConfigurationRepository { + + public void create(PlanConfigurationRequest planConfigurationRequest); + + public void update(PlanConfigurationRequest planConfigurationRequest); + +} diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java new file mode 100644 index 00000000000..2dc30af065a --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java @@ -0,0 +1,37 @@ +package digit.repository.impl; + +import digit.config.Configuration; +import digit.kafka.Producer; +import digit.repository.PlanConfigurationRepository; +import digit.web.models.PlanConfigurationRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; + +@Repository +@Slf4j +public class PlanConfigurationRepositoryImpl implements PlanConfigurationRepository { + + private Producer producer; + private JdbcTemplate jdbcTemplate; + private Configuration config; + + @Autowired + public PlanConfigurationRepositoryImpl(Producer producer, JdbcTemplate jdbcTemplate, + Configuration config) { + this.producer = producer; + this.jdbcTemplate = jdbcTemplate; + this.config = config; + } + + @Override + public void create(PlanConfigurationRequest planConfigurationRequest) { + producer.push(config.getPlanConfigCreateTopic(),planConfigurationRequest); + } + + @Override + public void update(PlanConfigurationRequest planConfigurationRequest) { + producer.push(config.getPlanConfigUpdateTopic(),planConfigurationRequest); + } +} diff --git a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java index dfd6006b3d4..c59e5bc4bf7 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java @@ -2,6 +2,8 @@ import digit.config.Configuration; import digit.kafka.Producer; +import digit.repository.PlanConfigurationRepository; +import digit.repository.impl.PlanConfigurationRepositoryImpl; import digit.service.enrichment.EnrichmentService; import digit.service.validator.PlanConfigurationValidator; import digit.web.models.PlanConfigurationRequest; @@ -21,17 +23,21 @@ public class PlanConfigurationService { private PlanConfigurationValidator validator; - public PlanConfigurationService(Producer producer, EnrichmentService enrichmentService, Configuration config, PlanConfigurationValidator validator) { + private PlanConfigurationRepositoryImpl repository; + + public PlanConfigurationService(Producer producer, EnrichmentService enrichmentService, Configuration config + , PlanConfigurationValidator validator, PlanConfigurationRepositoryImpl repository) { this.producer = producer; this.enrichmentService = enrichmentService; this.config = config; this.validator = validator; + this.repository = repository; } public PlanConfigurationRequest create(PlanConfigurationRequest request) { enrichmentService.enrichCreate(request); validator.validateCreate(request); - producer.push(config.getPlanConfigCreateTopic() ,request); + repository.create(request); return request; } } \ No newline at end of file diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index 56d097c68b6..8d7493df5df 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -1,14 +1,75 @@ package digit.service.validator; +import com.jayway.jsonpath.JsonPath; +import digit.util.MdmsUtil; +import digit.web.models.Assumption; +import digit.web.models.Operation; +import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; +import org.egov.tracer.model.CustomException; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import static digit.config.ServiceConstants.ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_CODE; +import static digit.config.ServiceConstants.ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_MESSAGE; +import static digit.config.ServiceConstants.ASSUMPTION_VALUE_NOT_FOUND_CODE; +import static digit.config.ServiceConstants.ASSUMPTION_VALUE_NOT_FOUND_MESSAGE; +import static digit.config.ServiceConstants.MDMS_MASTER_ASSUMPTION; +import static digit.config.ServiceConstants.MDMS_PLAN_ASSUMPTION_MODULE_NAME; + @Component @Slf4j public class PlanConfigurationValidator { - public void validateCreate(PlanConfigurationRequest request) { -// enrichPlanConfiguration(request.getPlanConfiguration()); + @Autowired + MdmsUtil mdmsUtil; + + public void validateCreate(PlanConfigurationRequest request) { +// validateAssumptionKeyAgainstMDMS(request); + validateAssumptionValue(request.getPlanConfiguration()); + } + + public void validateAssumptionValue(PlanConfiguration planConfiguration) { + Set assumptionValues = planConfiguration.getAssumptions().stream() + .map(Assumption::getKey) + .collect(Collectors.toSet()); + + List operations = planConfiguration.getOperations(); + for (Operation operation : operations) { + if (!assumptionValues.contains(operation.getAssumptionValue())) { + log.error("Assumption Value " + operation.getAssumptionValue() + " is not present in Assumption Key List"); + throw new CustomException(ASSUMPTION_VALUE_NOT_FOUND_CODE, ASSUMPTION_VALUE_NOT_FOUND_MESSAGE); + } + } } + + public void validateAssumptionKeyAgainstMDMS(PlanConfigurationRequest request) { + PlanConfiguration planConfiguration = request.getPlanConfiguration(); + String rootTenantId = planConfiguration.getTenantId().split("\\.")[0]; + Object mdmsData = mdmsUtil.fetchMdmsData(request.getRequestInfo(), rootTenantId, MDMS_PLAN_ASSUMPTION_MODULE_NAME, Collections.singletonList(MDMS_MASTER_ASSUMPTION)); + final String jsonPathForAssumption = "$.MdmsRes." + MDMS_PLAN_ASSUMPTION_MODULE_NAME + "." + MDMS_MASTER_ASSUMPTION + ".*"; + + List assumptionListFromMDMS = null; + try { + assumptionListFromMDMS = JsonPath.read(mdmsData, jsonPathForAssumption); + } catch (Exception e) { + log.error(e.getMessage()); + throw new CustomException("JSONPATH_ERROR", "Failed to parse mdms response"); + } + + for(Assumption assumption : planConfiguration.getAssumptions()) + { + if(!assumptionListFromMDMS.contains(assumption.getKey())) + { + log.error("Assumption Key " + assumption.getKey() + " is not present in MDMS"); + throw new CustomException(ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_CODE, ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_MESSAGE); + } + } + } + } diff --git a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java index 69fa8e26f03..131bcf71afc 100644 --- a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java @@ -37,7 +37,6 @@ public Object fetchMdmsData(RequestInfo requestInfo, String tenantId, String mod uri.append(configs.getMdmsHost()).append(configs.getMdmsEndPoint()); MdmsCriteriaReq mdmsCriteriaReq = getMdmsRequest(requestInfo, tenantId, moduleName, masterNameList); Object response = new HashMap<>(); - Integer rate = 0; MdmsResponse mdmsResponse = new MdmsResponse(); try { response = restTemplate.postForObject(uri.toString(), mdmsCriteriaReq, Map.class); @@ -47,7 +46,6 @@ public Object fetchMdmsData(RequestInfo requestInfo, String tenantId, String mod } return mdmsResponse.getMdmsRes(); - //log.info(ulbToCategoryListMap.toString()); } private MdmsCriteriaReq getMdmsRequest(RequestInfo requestInfo, String tenantId, String moduleName, List masterNameList) { diff --git a/health-services/project/src/main/java/org/egov/project/validator/project/ProjectValidator.java b/health-services/project/src/main/java/org/egov/project/validator/project/ProjectValidator.java index 754fbc26fbe..9073d14e35a 100644 --- a/health-services/project/src/main/java/org/egov/project/validator/project/ProjectValidator.java +++ b/health-services/project/src/main/java/org/egov/project/validator/project/ProjectValidator.java @@ -324,7 +324,6 @@ private void validateAttendanceSessionAgainstMDMS(ProjectRequest projectRequest, ObjectMapper objectMapper = new ObjectMapper(); String numberOfSessions = null; - //Get MDMS data using create project request and tenantId Object mdmsData = mdmsUtils.mDMSCall(projectRequest, rootTenantId); final String jsonPathForAttendanceSession = "$.MdmsRes." + MDMS_HCM_ATTENDANCE_MODULE_NAME + "." + MASTER_ATTENDANCE_SESSION + ".*"; List attendanceRes = null; From 8f644bb9b458c3ca16192ee689d0bf6940dc3818 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 6 Mar 2024 17:53:24 +0530 Subject: [PATCH 11/53] HLM-5184 removing digit.models import --- health-services/plan-service/pom.xml | 5 ----- .../java/digit/service/enrichment/EnrichmentService.java | 2 +- .../src/main/java/digit/web/models/Assumption.java | 3 +-- .../plan-service/src/main/java/digit/web/models/File.java | 2 +- .../src/main/java/digit/web/models/Operation.java | 4 ++-- .../src/main/java/digit/web/models/PlanConfiguration.java | 2 +- .../src/main/java/digit/web/models/ResourceMapping.java | 2 +- 7 files changed, 7 insertions(+), 13 deletions(-) diff --git a/health-services/plan-service/pom.xml b/health-services/plan-service/pom.xml index 5cdd3f77b6e..88c0d179a85 100644 --- a/health-services/plan-service/pom.xml +++ b/health-services/plan-service/pom.xml @@ -79,11 +79,6 @@ tracer 2.9.0-SNAPSHOT - - org.egov.services - digit-models - 1.0.0-SNAPSHOT - org.egov mdms-client diff --git a/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java b/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java index 11f4dc01a7b..edee865e07c 100644 --- a/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java @@ -1,7 +1,6 @@ package digit.service.enrichment; import digit.config.Configuration; -import digit.models.coremodels.AuditDetails; import digit.web.models.Assumption; import digit.web.models.File; import digit.web.models.Operation; @@ -11,6 +10,7 @@ import java.util.List; import java.util.UUID; import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.models.AuditDetails; import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Service; diff --git a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java index 57885e85349..f41c3e592a1 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java @@ -1,11 +1,10 @@ package digit.web.models; -import digit.models.coremodels.AuditDetails; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import java.math.BigDecimal; import java.util.UUID; +import org.egov.common.contract.models.AuditDetails; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; import javax.validation.constraints.*; diff --git a/health-services/plan-service/src/main/java/digit/web/models/File.java b/health-services/plan-service/src/main/java/digit/web/models/File.java index 6067c56a3ba..63046fff609 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/File.java +++ b/health-services/plan-service/src/main/java/digit/web/models/File.java @@ -1,12 +1,12 @@ package digit.web.models; -import digit.models.coremodels.AuditDetails; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.v3.oas.annotations.media.Schema; import java.util.UUID; +import org.egov.common.contract.models.AuditDetails; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; import javax.validation.constraints.*; diff --git a/health-services/plan-service/src/main/java/digit/web/models/Operation.java b/health-services/plan-service/src/main/java/digit/web/models/Operation.java index 6518daba2a5..4c7550e8d32 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Operation.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Operation.java @@ -1,12 +1,12 @@ package digit.web.models; -import digit.models.coremodels.AuditDetails; -import java.util.Objects; + import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.v3.oas.annotations.media.Schema; import java.util.UUID; +import org.egov.common.contract.models.AuditDetails; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; import javax.validation.constraints.*; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java index d3637ba09d2..13dde3c3f25 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java @@ -1,10 +1,10 @@ package digit.web.models; -import digit.models.coremodels.AuditDetails; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.ArrayList; import java.util.List; import java.util.UUID; +import org.egov.common.contract.models.AuditDetails; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; import javax.validation.constraints.*; diff --git a/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java index ecfaad17e63..5a9eb164353 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java +++ b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java @@ -1,10 +1,10 @@ package digit.web.models; -import digit.models.coremodels.AuditDetails; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.v3.oas.annotations.media.Schema; +import org.egov.common.contract.models.AuditDetails; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; import javax.validation.constraints.*; From face0ab3dc57d027485d94261b1eab77b5f82648 Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Thu, 7 Mar 2024 11:59:32 +0530 Subject: [PATCH 12/53] [HLM-5129] Added validations and made changes in database migration file for plan service --- .../main/java/digit/service/PlanEnricher.java | 19 +++++++++++++ .../java/digit/service/PlanValidator.java | 15 ++++++++-- .../main/java/digit/web/models/Activity.java | 2 +- .../main/java/digit/web/models/Condition.java | 5 +++- .../java/digit/web/models/MetricDetail.java | 28 +++++++++++++++++++ .../main/java/digit/web/models/Target.java | 9 ++---- .../main/V20240305113047__plan_create_ddl.sql | 22 ++++----------- 7 files changed, 73 insertions(+), 27 deletions(-) create mode 100644 health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java diff --git a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java index 3bacba9d5cb..5eaf5f1430c 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java @@ -3,12 +3,31 @@ import digit.web.models.PlanCreateRequest; import org.egov.common.utils.UUIDEnrichmentUtil; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; @Component public class PlanEnricher { public void enrichPlanCreate(PlanCreateRequest body) { + // Generate id for plan UUIDEnrichmentUtil.enrichRandomUuid(body.getPlan(), "id"); + + // Generate id for activities + body.getPlan().getActivities().forEach(activity -> UUIDEnrichmentUtil.enrichRandomUuid(activity, "id")); + + // Generate id for activity conditions + body.getPlan().getActivities().forEach(activity -> { + if(!CollectionUtils.isEmpty(activity.getConditions())) { + UUIDEnrichmentUtil.enrichRandomUuid(activity.getConditions(), "id"); + } + }); + + // Generate id for resources + body.getPlan().getResources().forEach(resource -> UUIDEnrichmentUtil.enrichRandomUuid(resource, "id")); + + // Generate id for targets + body.getPlan().getTargets().forEach(target -> UUIDEnrichmentUtil.enrichRandomUuid(target, "id")); + } } diff --git a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java index 86d1ae5103a..4834d5d20b9 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java @@ -7,6 +7,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -48,8 +49,9 @@ private void validateActivityDependencies(PlanCreateRequest request) { } private void checkForCycleInActivityDependencies(PlanCreateRequest request) { - Map> activityCodeVsDependenciesMap = request.getPlan().getActivities().stream() - .collect(Collectors.toMap(Activity::getCode, Activity::getDependencies)); + Map> activityCodeVsDependenciesMap = request.getPlan().getActivities().stream() + .collect(Collectors.toMap(Activity::getCode, + activity -> CollectionUtils.isEmpty(activity.getDependencies()) ? List.of() : activity.getDependencies())); activityCodeVsDependenciesMap.keySet().forEach(activityCode -> { activityCodeVsDependenciesMap.get(activityCode).forEach(dependency -> { @@ -77,6 +79,15 @@ private void validateExecutionPlanExistence(PlanCreateRequest request) { } private void validateActivities(PlanCreateRequest request) { + // Validate code uniqueness within activities + Set activityCodes = request.getPlan().getActivities().stream() + .map(Activity::getCode) + .collect(Collectors.toSet()); + + if(activityCodes.size() != request.getPlan().getActivities().size()) { + throw new CustomException("DUPLICATE_ACTIVITY_CODES", "Activity codes within the plan should be unique"); + } + // If execution plan id is not provided, providing activities is mandatory if(ObjectUtils.isEmpty(request.getPlan().getExecutionPlanId()) && CollectionUtils.isEmpty(request.getPlan().getActivities())) { diff --git a/health-services/plan-service/src/main/java/digit/web/models/Activity.java b/health-services/plan-service/src/main/java/digit/web/models/Activity.java index 300766b28dd..6260a5955d9 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Activity.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Activity.java @@ -39,7 +39,7 @@ public class Activity { private Long plannedEndDate = null; @JsonProperty("dependencies") - private Set dependencies = null; + private List dependencies = null; @JsonProperty("conditions") @Valid diff --git a/health-services/plan-service/src/main/java/digit/web/models/Condition.java b/health-services/plan-service/src/main/java/digit/web/models/Condition.java index ba26b6224d4..326443be599 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Condition.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Condition.java @@ -21,6 +21,10 @@ @NoArgsConstructor @Builder public class Condition { + + @JsonProperty + private String id = null; + @JsonProperty("entity") private String entity = null; @@ -30,5 +34,4 @@ public class Condition { @JsonProperty("expression") private String expression = null; - } diff --git a/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java b/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java new file mode 100644 index 00000000000..6a0989ec15c --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java @@ -0,0 +1,28 @@ +package digit.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.validation.annotation.Validated; + +import java.math.BigDecimal; + +@Validated +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class MetricDetail { + + @JsonProperty("value") + private BigDecimal metricValue = null; + + @JsonProperty("comparator") + private String metricComparator = null; + + @JsonProperty("unit") + private String metricUnit = null; + +} diff --git a/health-services/plan-service/src/main/java/digit/web/models/Target.java b/health-services/plan-service/src/main/java/digit/web/models/Target.java index c4124b8d18b..4a9cd7d1fa8 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Target.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Target.java @@ -22,19 +22,16 @@ @NoArgsConstructor @Builder public class Target { - @JsonProperty("id") - @Valid - private UUID id = null; - @JsonProperty("taskId") + @JsonProperty("id") @Valid - private UUID taskId = null; + private String id = null; @JsonProperty("metric") private String metric = null; @JsonProperty("metricDetail") - private Object metricDetail = null; + private MetricDetail metricDetail = null; @JsonProperty("activityCode") private String activityCode = null; diff --git a/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql b/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql index e19b8a66bf2..1a32db805c5 100644 --- a/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql +++ b/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql @@ -13,14 +13,13 @@ CREATE TABLE plan ( ); CREATE TABLE plan_activity ( - id varchar(64), - tenant_id varchar(64), - code varchar(128), + id varchar(64) NOT NULL, + code varchar(128) NOT NULL, description varchar(2048), planned_start_date bigint, planned_end_date bigint, - plan_id varchar(64), - resource_id varchar(64), + dependencies character varying(2048), + plan_id varchar(64) NOT NULL, created_by varchar(64), created_time bigint, last_modified_by varchar(64), @@ -29,24 +28,13 @@ CREATE TABLE plan_activity ( FOREIGN KEY (plan_id) REFERENCES plan(id) ); -CREATE TABLE plan_activity_dependency ( - id varchar(64), - activity_id varchar(64), - precursor_activity_code varchar(64), - created_by varchar(64), - created_time bigint, - last_modified_by varchar(64), - last_modified_time bigint, - CONSTRAINT uk_plan_activity_dependency_id PRIMARY KEY (id), - FOREIGN KEY (activity_id) REFERENCES plan_activity(id) -); - CREATE TABLE plan_activity_condition ( id varchar(64), entity varchar(64), entity_property varchar(64), expression varchar(2048), activity_id varchar(64), + is_active boolean, created_by varchar(64), created_time bigint, last_modified_by varchar(64), From 93ef7b41837cdf7d88d04ded271da68f30e5527a Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Thu, 7 Mar 2024 12:39:56 +0530 Subject: [PATCH 13/53] [HLM-5129] Added plan repository interface and its implementation classes --- .../java/digit/repository/PlanRepository.java | 13 ++++++++ .../repository/impl/PlanRepositoryImpl.java | 32 +++++++++++++++++++ .../main/java/digit/service/PlanEnricher.java | 9 ++++-- .../main/java/digit/service/PlanService.java | 4 +-- .../java/digit/service/PlanValidator.java | 22 ++++++------- .../digit/web/controllers/PlanController.java | 2 +- .../src/main/java/digit/web/models/Plan.java | 5 +++ ...lanCreateRequest.java => PlanRequest.java} | 2 +- 8 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 health-services/plan-service/src/main/java/digit/repository/PlanRepository.java create mode 100644 health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java rename health-services/plan-service/src/main/java/digit/web/models/{PlanCreateRequest.java => PlanRequest.java} (94%) diff --git a/health-services/plan-service/src/main/java/digit/repository/PlanRepository.java b/health-services/plan-service/src/main/java/digit/repository/PlanRepository.java new file mode 100644 index 00000000000..423129b9174 --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/repository/PlanRepository.java @@ -0,0 +1,13 @@ +package digit.repository; + +import digit.web.models.PlanRequest; +import digit.web.models.PlanSearchCriteria; + +public interface PlanRepository { + public void create(PlanRequest planRequest); + + public void search(PlanSearchCriteria planSearchCriteria); + + public void update(PlanRequest planRequest); + +} diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java new file mode 100644 index 00000000000..0f3df939455 --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java @@ -0,0 +1,32 @@ +package digit.repository.impl; + +import digit.kafka.Producer; +import digit.repository.PlanRepository; +import digit.web.models.PlanRequest; +import digit.web.models.PlanSearchCriteria; +import org.springframework.stereotype.Repository; + +@Repository +public class PlanRepositoryImpl implements PlanRepository { + + private Producer producer; + + public PlanRepositoryImpl(Producer producer) { + this.producer = producer; + } + + @Override + public void create(PlanRequest planRequest) { + producer.push("save-plan", planRequest); + } + + @Override + public void search(PlanSearchCriteria planSearchCriteria) { + + } + + @Override + public void update(PlanRequest planRequest) { + producer.push("update-plan", planRequest); + } +} diff --git a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java index 5eaf5f1430c..84fcefc9439 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java @@ -1,6 +1,7 @@ package digit.service; -import digit.web.models.PlanCreateRequest; +import digit.web.models.PlanRequest; +import org.egov.common.utils.AuditDetailsEnrichmentUtil; import org.egov.common.utils.UUIDEnrichmentUtil; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -9,7 +10,7 @@ public class PlanEnricher { - public void enrichPlanCreate(PlanCreateRequest body) { + public void enrichPlanCreate(PlanRequest body) { // Generate id for plan UUIDEnrichmentUtil.enrichRandomUuid(body.getPlan(), "id"); @@ -29,5 +30,9 @@ public void enrichPlanCreate(PlanCreateRequest body) { // Generate id for targets body.getPlan().getTargets().forEach(target -> UUIDEnrichmentUtil.enrichRandomUuid(target, "id")); + // Enrich audit details + body.getPlan().setAuditDetails(AuditDetailsEnrichmentUtil + .prepareAuditDetails(body.getPlan().getAuditDetails(), body.getRequestInfo(), Boolean.TRUE)); + } } diff --git a/health-services/plan-service/src/main/java/digit/service/PlanService.java b/health-services/plan-service/src/main/java/digit/service/PlanService.java index 7552b738ce8..8cc7d9b85e9 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanService.java @@ -1,6 +1,6 @@ package digit.service; -import digit.web.models.PlanCreateRequest; +import digit.web.models.PlanRequest; import digit.web.models.PlanResponse; import org.egov.common.utils.ResponseInfoUtil; import org.springframework.stereotype.Service; @@ -19,7 +19,7 @@ public PlanService(PlanValidator planValidator, PlanEnricher planEnricher) { this.planEnricher = planEnricher; } - public PlanResponse createPlan(PlanCreateRequest body) { + public PlanResponse createPlan(PlanRequest body) { // Validate plan create request planValidator.validatePlanCreate(body); diff --git a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java index 4834d5d20b9..4a78914d6fe 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java @@ -1,7 +1,7 @@ package digit.service; import digit.web.models.Activity; -import digit.web.models.PlanCreateRequest; +import digit.web.models.PlanRequest; import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -15,7 +15,7 @@ @Component public class PlanValidator { - public void validatePlanCreate(PlanCreateRequest request) { + public void validatePlanCreate(PlanRequest request) { // Validate execution plan existence validateExecutionPlanExistence(request); @@ -40,7 +40,7 @@ public void validatePlanCreate(PlanCreateRequest request) { } - private void validateActivityDependencies(PlanCreateRequest request) { + private void validateActivityDependencies(PlanRequest request) { // Check if dependent activity codes are valid validateDependentActivityCodes(request); @@ -48,7 +48,7 @@ private void validateActivityDependencies(PlanCreateRequest request) { checkForCycleInActivityDependencies(request); } - private void checkForCycleInActivityDependencies(PlanCreateRequest request) { + private void checkForCycleInActivityDependencies(PlanRequest request) { Map> activityCodeVsDependenciesMap = request.getPlan().getActivities().stream() .collect(Collectors.toMap(Activity::getCode, activity -> CollectionUtils.isEmpty(activity.getDependencies()) ? List.of() : activity.getDependencies())); @@ -61,7 +61,7 @@ private void checkForCycleInActivityDependencies(PlanCreateRequest request) { }); } - private void validateDependentActivityCodes(PlanCreateRequest request) { + private void validateDependentActivityCodes(PlanRequest request) { request.getPlan().getActivities().forEach(activity -> { if(!CollectionUtils.isEmpty(activity.getDependencies())) { Set activityCodes = request.getPlan().getActivities().stream() @@ -75,10 +75,10 @@ private void validateDependentActivityCodes(PlanCreateRequest request) { }); } - private void validateExecutionPlanExistence(PlanCreateRequest request) { + private void validateExecutionPlanExistence(PlanRequest request) { } - private void validateActivities(PlanCreateRequest request) { + private void validateActivities(PlanRequest request) { // Validate code uniqueness within activities Set activityCodes = request.getPlan().getActivities().stream() .map(Activity::getCode) @@ -109,11 +109,11 @@ private void validateActivities(PlanCreateRequest request) { } } - private void validatePlanConfigurationExistence(PlanCreateRequest request) { + private void validatePlanConfigurationExistence(PlanRequest request) { } - private void validateResources(PlanCreateRequest request) { + private void validateResources(PlanRequest request) { // If plan configuration id is not provided, providing resources is mandatory if(ObjectUtils.isEmpty(request.getPlan().getPlanConfigurationId()) && CollectionUtils.isEmpty(request.getPlan().getResources())) { @@ -134,7 +134,7 @@ private void validateResources(PlanCreateRequest request) { } } - private void validateResourceActivityLinkage(PlanCreateRequest request) { + private void validateResourceActivityLinkage(PlanRequest request) { if(!CollectionUtils.isEmpty(request.getPlan().getActivities())) { Set activityCodes = request.getPlan().getActivities().stream() .map(Activity::getCode) @@ -146,7 +146,7 @@ private void validateResourceActivityLinkage(PlanCreateRequest request) { } } - private void validateTargetActivityLinkage(PlanCreateRequest request) { + private void validateTargetActivityLinkage(PlanRequest request) { if(!CollectionUtils.isEmpty(request.getPlan().getActivities())) { Set activityCodes = request.getPlan().getActivities().stream() .map(Activity::getCode) diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java index 12b266628d9..077d848f91c 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java @@ -23,7 +23,7 @@ public PlanController(PlanService planService) { } @RequestMapping(value = "/_create", method = RequestMethod.POST) - public ResponseEntity createPost(@Valid @RequestBody PlanCreateRequest body) { + public ResponseEntity createPost(@Valid @RequestBody PlanRequest body) { PlanResponse planResponse = planService.createPlan(body); return ResponseEntity.status(HttpStatus.ACCEPTED).body(planResponse); } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Plan.java b/health-services/plan-service/src/main/java/digit/web/models/Plan.java index 1f3f6db4418..dda77614398 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Plan.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Plan.java @@ -2,6 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; + +import org.egov.common.contract.models.AuditDetails; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; import javax.validation.constraints.*; @@ -51,4 +53,7 @@ public class Plan { @Valid private List targets = null; + @JsonProperty("auditDetails") + private AuditDetails auditDetails = null; + } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanRequest.java similarity index 94% rename from health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java rename to health-services/plan-service/src/main/java/digit/web/models/PlanRequest.java index 8b55bd1b722..d1a037a3815 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanCreateRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanRequest.java @@ -17,7 +17,7 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PlanCreateRequest { +public class PlanRequest { @JsonProperty("RequestInfo") @Valid private RequestInfo requestInfo = null; From 547d1a70843ac497ab68cabb0ffe450266118bf2 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 7 Mar 2024 16:02:52 +0530 Subject: [PATCH 14/53] HLM-5184 adding modifications for validations and enrichments. --- .../PlanConfigurationRepository.java | 5 ++- .../repository/ServiceRequestRepository.java | 2 - .../impl/PlanConfigurationRepositoryImpl.java | 6 ++- .../service/enrichment/EnrichmentService.java | 44 +++++-------------- .../web/controllers/PlanConfigController.java | 2 +- .../java/digit/web/models/Assumption.java | 6 +-- .../src/main/java/digit/web/models/File.java | 6 +-- .../main/java/digit/web/models/Operation.java | 8 ++-- .../digit/web/models/PlanConfiguration.java | 23 +--------- .../web/models/PlanConfigurationResponse.java | 10 ++--- .../digit/web/models/ResourceMapping.java | 8 ++-- ...5113045__plan_configuration_create_ddl.sql | 4 +- 12 files changed, 37 insertions(+), 87 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/repository/PlanConfigurationRepository.java b/health-services/plan-service/src/main/java/digit/repository/PlanConfigurationRepository.java index 658c91afce3..d0e303e4650 100644 --- a/health-services/plan-service/src/main/java/digit/repository/PlanConfigurationRepository.java +++ b/health-services/plan-service/src/main/java/digit/repository/PlanConfigurationRepository.java @@ -4,11 +4,14 @@ import digit.web.models.PlanConfigurationRequest; import org.springframework.stereotype.Repository; -@Repository + public interface PlanConfigurationRepository { public void create(PlanConfigurationRequest planConfigurationRequest); + public void search(PlanConfigurationRequest planConfigurationRequest); + public void update(PlanConfigurationRequest planConfigurationRequest); + } diff --git a/health-services/plan-service/src/main/java/digit/repository/ServiceRequestRepository.java b/health-services/plan-service/src/main/java/digit/repository/ServiceRequestRepository.java index 7a2ebeeca71..d09d230e4fa 100644 --- a/health-services/plan-service/src/main/java/digit/repository/ServiceRequestRepository.java +++ b/health-services/plan-service/src/main/java/digit/repository/ServiceRequestRepository.java @@ -22,8 +22,6 @@ public class ServiceRequestRepository { private RestTemplate restTemplate; - - @Autowired public ServiceRequestRepository(ObjectMapper mapper, RestTemplate restTemplate) { this.mapper = mapper; this.restTemplate = restTemplate; diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java index 2dc30af065a..b086b764e74 100644 --- a/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java @@ -17,7 +17,6 @@ public class PlanConfigurationRepositoryImpl implements PlanConfigurationReposit private JdbcTemplate jdbcTemplate; private Configuration config; - @Autowired public PlanConfigurationRepositoryImpl(Producer producer, JdbcTemplate jdbcTemplate, Configuration config) { this.producer = producer; @@ -30,6 +29,11 @@ public void create(PlanConfigurationRequest planConfigurationRequest) { producer.push(config.getPlanConfigCreateTopic(),planConfigurationRequest); } + @Override + public void search(PlanConfigurationRequest planConfigurationRequest) { + log.info("Search Method"); + } + @Override public void update(PlanConfigurationRequest planConfigurationRequest) { producer.push(config.getPlanConfigUpdateTopic(),planConfigurationRequest); diff --git a/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java b/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java index edee865e07c..3dd78e2bbb9 100644 --- a/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java @@ -11,14 +11,15 @@ import java.util.UUID; import lombok.extern.slf4j.Slf4j; import org.egov.common.contract.models.AuditDetails; +import org.egov.common.utils.UUIDEnrichmentUtil; import org.egov.tracer.model.CustomException; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import static digit.config.ServiceConstants.USERINFO_MISSING_CODE; import static digit.config.ServiceConstants.USERINFO_MISSING_MESSAGE; -@Service +@Component @Slf4j public class EnrichmentService { private Configuration config; @@ -35,44 +36,19 @@ public void enrichCreate(PlanConfigurationRequest request) { enrichAuditDetails(request.getPlanConfiguration(), request.getRequestInfo().getUserInfo().getUuid(), Boolean.TRUE); } - public PlanConfiguration enrichPlanConfiguration(PlanConfiguration planConfiguration) { + public void enrichPlanConfiguration(PlanConfiguration planConfiguration) { log.info("enriching plan config with generated IDs"); + UUIDEnrichmentUtil.enrichRandomUuid(planConfiguration, "id"); + UUIDEnrichmentUtil.enrichRandomUuid(planConfiguration.getFiles(), "id"); + UUIDEnrichmentUtil.enrichRandomUuid(planConfiguration.getAssumptions(), "id"); + UUIDEnrichmentUtil.enrichRandomUuid(planConfiguration.getOperations(), "id"); + UUIDEnrichmentUtil.enrichRandomUuid(planConfiguration.getResourceMapping(), "id"); - // Set ID for PlanConfiguration - planConfiguration.setId(UUID.randomUUID()); - - // Set IDs for Assumptions - List assumptions = planConfiguration.getAssumptions(); - for (Assumption assumption : assumptions) { - assumption.setId(UUID.randomUUID()); - } - - // Set IDs for Operations - List operations = planConfiguration.getOperations(); - for (Operation operation : operations) { - operation.setId(UUID.randomUUID()); - } - - return planConfiguration; } public void enrichAuditDetails(PlanConfiguration planConfiguration, String by, Boolean isCreate) { Long time = System.currentTimeMillis(); - for (Operation operation : planConfiguration.getOperations()) { - operation.setAuditDetails(getAuditDetails(by, operation.getAuditDetails(), isCreate)); - } - - for (Assumption assumption : planConfiguration.getAssumptions()) { - assumption.setAuditDetails(getAuditDetails(by, assumption.getAuditDetails(), isCreate)); - } - - for (File file : planConfiguration.getFiles()) { - file.setAuditDetails(getAuditDetails(by, file.getAuditDetails(), isCreate)); - } - - for (ResourceMapping resourceMapping : planConfiguration.getResourceMapping()) { - resourceMapping.setAuditDetails(getAuditDetails(by, resourceMapping.getAuditDetails(), isCreate)); - } + planConfiguration.setAuditDetails(getAuditDetails(by,planConfiguration.getAuditDetails(), isCreate)); } public AuditDetails getAuditDetails(String by, AuditDetails auditDetails, Boolean isCreate) { diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java index 16798719446..452c6146eb5 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java @@ -38,7 +38,7 @@ public ResponseEntity configCreatePost(@Parameter(in PlanConfigurationRequest planConfigurationRequest = planConfigurationService.create(body); PlanConfigurationResponse response = PlanConfigurationResponse.builder() - .planConfigurationResponse(Collections.singletonList(planConfigurationRequest.getPlanConfiguration())) + .planConfiguration(Collections.singletonList(planConfigurationRequest.getPlanConfiguration())) .responseInfo(new ResponseInfo()) .build(); diff --git a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java index f41c3e592a1..3d9b0f3cb49 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java @@ -24,7 +24,7 @@ public class Assumption { @JsonProperty("id") @Valid - private UUID id = null; + private String id = null; @JsonProperty("key") @NotNull @@ -36,8 +36,4 @@ public class Assumption { @Valid private BigDecimal value = null; - @JsonProperty("auditDetails") - private @Valid AuditDetails auditDetails; - - } diff --git a/health-services/plan-service/src/main/java/digit/web/models/File.java b/health-services/plan-service/src/main/java/digit/web/models/File.java index 63046fff609..a9cee864e70 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/File.java +++ b/health-services/plan-service/src/main/java/digit/web/models/File.java @@ -26,7 +26,7 @@ public class File { @JsonProperty("id") @Valid - private UUID id = null; + private String id = null; @JsonProperty("filestoreId") @NotNull @@ -37,10 +37,6 @@ public class File { @NotNull private InputFileTypeEnum inputFileType = null; - @JsonProperty("auditDetails") - private @Valid AuditDetails auditDetails; - - /** * The original file type of the Input */ diff --git a/health-services/plan-service/src/main/java/digit/web/models/Operation.java b/health-services/plan-service/src/main/java/digit/web/models/Operation.java index 4c7550e8d32..90a12e200ac 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Operation.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Operation.java @@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.v3.oas.annotations.media.Schema; +import java.math.BigDecimal; +import java.math.BigInteger; import java.util.UUID; import org.egov.common.contract.models.AuditDetails; import org.springframework.validation.annotation.Validated; @@ -26,7 +28,7 @@ public class Operation { @JsonProperty("id") @Valid - private UUID id = null; + private String id = null; @JsonProperty("input") @NotNull @@ -44,10 +46,6 @@ public class Operation { @Size(min = 1, max = 32) private String output = null; - @JsonProperty("auditDetails") - private @Valid AuditDetails auditDetails; - - /** * The operator used in the operation */ diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java index 13dde3c3f25..e29be80616f 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java @@ -23,9 +23,8 @@ @Builder public class PlanConfiguration { @JsonProperty("id") - @Valid - private UUID id = null; + private String id = null; @JsonProperty("tenantId") @NotNull @@ -62,24 +61,4 @@ public class PlanConfiguration { @JsonProperty("auditDetails") private @Valid AuditDetails auditDetails; - public PlanConfiguration addFilesItem(File filesItem) { - this.files.add(filesItem); - return this; - } - - public PlanConfiguration addAssumptionsItem(Assumption assumptionsItem) { - this.assumptions.add(assumptionsItem); - return this; - } - - public PlanConfiguration addOperationsItem(Operation operationsItem) { - this.operations.add(operationsItem); - return this; - } - - public PlanConfiguration addResourceMappingItem(ResourceMapping resourceMappingItem) { - this.resourceMapping.add(resourceMappingItem); - return this; - } - } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java index 1ac7464b8f2..6948daa8cca 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java @@ -24,16 +24,16 @@ public class PlanConfigurationResponse { @Valid private ResponseInfo responseInfo = null; - @JsonProperty("PlanConfigurationResponse") + @JsonProperty("PlanConfiguration") @Valid - private List planConfigurationResponse = null; + private List planConfiguration = null; public PlanConfigurationResponse addPlanConfigurationResponseItem(PlanConfiguration planConfigurationResponseItem) { - if (this.planConfigurationResponse == null) { - this.planConfigurationResponse = new ArrayList<>(); + if (this.planConfiguration == null) { + this.planConfiguration = new ArrayList<>(); } - this.planConfigurationResponse.add(planConfigurationResponseItem); + this.planConfiguration.add(planConfigurationResponseItem); return this; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java index 5a9eb164353..278b25e7d07 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java +++ b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java @@ -22,14 +22,14 @@ @NoArgsConstructor @Builder public class ResourceMapping { + @JsonProperty("id") + @Valid + private String id = null; + @JsonProperty("mappedFrom") private String mappedFrom = null; @JsonProperty("mappedTo") private String mappedTo = null; - @JsonProperty("auditDetails") - private @Valid AuditDetails auditDetails; - - } diff --git a/health-services/plan-service/src/main/resources/db/migration/main/V20240305113045__plan_configuration_create_ddl.sql b/health-services/plan-service/src/main/resources/db/migration/main/V20240305113045__plan_configuration_create_ddl.sql index 5471368869b..e9630421bcb 100644 --- a/health-services/plan-service/src/main/resources/db/migration/main/V20240305113045__plan_configuration_create_ddl.sql +++ b/health-services/plan-service/src/main/resources/db/migration/main/V20240305113045__plan_configuration_create_ddl.sql @@ -31,7 +31,7 @@ CREATE TABLE plan_configuration_files ( CREATE TABLE plan_configuration_assumptions ( id character varying(64), key character varying(256), - value character varying(256), + value numeric(12,2), plan_configuration_id character varying(64), created_by character varying(64), created_time bigint, @@ -47,7 +47,7 @@ CREATE TABLE plan_configuration_operations ( id character varying(64), input character varying(256), operator character varying(64), - assumption_value bigint, + assumption_value character varying(256), output character varying(64), plan_configuration_id character varying(64), created_by character varying(64), From 2c11b369afd61ebf37b49d38b8c70a82c4a99316 Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Thu, 7 Mar 2024 16:03:55 +0530 Subject: [PATCH 15/53] [HLM-5129] Added enrichment and validations in plan create API --- .../src/main/java/digit/service/PlanEnricher.java | 12 ++++++++++++ .../src/main/java/digit/service/PlanService.java | 8 +++++++- .../src/main/java/digit/service/PlanValidator.java | 3 ++- .../java/digit/web/controllers/PlanController.java | 2 +- .../main/V20240305113047__plan_create_ddl.sql | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java index 84fcefc9439..c24eb800032 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java @@ -6,6 +6,9 @@ import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import java.util.ArrayList; +import java.util.List; + @Component public class PlanEnricher { @@ -24,6 +27,15 @@ public void enrichPlanCreate(PlanRequest body) { } }); + // Set empty value in dependencies list when it is empty or null + body.getPlan().getActivities().forEach(activity -> { + if(CollectionUtils.isEmpty(activity.getDependencies())) { + List emptyStringList = new ArrayList<>(); + emptyStringList.add(""); + activity.setDependencies(emptyStringList); + } + }); + // Generate id for resources body.getPlan().getResources().forEach(resource -> UUIDEnrichmentUtil.enrichRandomUuid(resource, "id")); diff --git a/health-services/plan-service/src/main/java/digit/service/PlanService.java b/health-services/plan-service/src/main/java/digit/service/PlanService.java index 8cc7d9b85e9..305800ef373 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanService.java @@ -1,5 +1,6 @@ package digit.service; +import digit.repository.PlanRepository; import digit.web.models.PlanRequest; import digit.web.models.PlanResponse; import org.egov.common.utils.ResponseInfoUtil; @@ -14,9 +15,12 @@ public class PlanService { private PlanEnricher planEnricher; - public PlanService(PlanValidator planValidator, PlanEnricher planEnricher) { + private PlanRepository planRepository; + + public PlanService(PlanValidator planValidator, PlanEnricher planEnricher, PlanRepository planRepository) { this.planValidator = planValidator; this.planEnricher = planEnricher; + this.planRepository = planRepository; } public PlanResponse createPlan(PlanRequest body) { @@ -27,6 +31,8 @@ public PlanResponse createPlan(PlanRequest body) { // Enrich plan create request planEnricher.enrichPlanCreate(body); + planRepository.create(body); + return PlanResponse.builder() .responseInfo(ResponseInfoUtil.createResponseInfoFromRequestInfo(body.getRequestInfo(), Boolean.TRUE)) .plan(Collections.singletonList(body.getPlan())) diff --git a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java index 4a78914d6fe..c293ee739a6 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java @@ -135,7 +135,8 @@ private void validateResources(PlanRequest request) { } private void validateResourceActivityLinkage(PlanRequest request) { - if(!CollectionUtils.isEmpty(request.getPlan().getActivities())) { + if(ObjectUtils.isEmpty(request.getPlan().getPlanConfigurationId()) + && !CollectionUtils.isEmpty(request.getPlan().getActivities())) { Set activityCodes = request.getPlan().getActivities().stream() .map(Activity::getCode) .collect(Collectors.toSet()); diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java index 077d848f91c..69946277d34 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java @@ -30,7 +30,7 @@ public ResponseEntity createPost(@Valid @RequestBody PlanRequest b @RequestMapping(value = "/_search", method = RequestMethod.POST) public ResponseEntity searchPost(@Valid @RequestBody PlanSearchRequest body) { - return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanResponse()); + return ResponseEntity.status(HttpStatus.OK).body(new PlanResponse()); } @RequestMapping(value = "/_update", method = RequestMethod.POST) diff --git a/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql b/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql index 1a32db805c5..942cc36af38 100644 --- a/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql +++ b/health-services/plan-service/src/main/resources/db/migration/main/V20240305113047__plan_create_ddl.sql @@ -34,7 +34,7 @@ CREATE TABLE plan_activity_condition ( entity_property varchar(64), expression varchar(2048), activity_id varchar(64), - is_active boolean, + is_active boolean DEFAULT true, created_by varchar(64), created_time bigint, last_modified_by varchar(64), From fc80c8e6a8c07fdce476f54e551f9da20bb6dd42 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 7 Mar 2024 16:13:44 +0530 Subject: [PATCH 16/53] HLM-5184 adding modifications for validations and enrichments. --- .../service/enrichment/EnrichmentService.java | 36 ++++++++++--------- .../src/main/resources/application.properties | 8 +++-- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java b/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java index 3dd78e2bbb9..14ee802dc3e 100644 --- a/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java @@ -11,6 +11,7 @@ import java.util.UUID; import lombok.extern.slf4j.Slf4j; import org.egov.common.contract.models.AuditDetails; +import org.egov.common.utils.AuditDetailsEnrichmentUtil; import org.egov.common.utils.UUIDEnrichmentUtil; import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Component; @@ -33,30 +34,33 @@ public void enrichCreate(PlanConfigurationRequest request) { if(request.getRequestInfo().getUserInfo() == null) throw new CustomException(USERINFO_MISSING_CODE, USERINFO_MISSING_MESSAGE); - enrichAuditDetails(request.getPlanConfiguration(), request.getRequestInfo().getUserInfo().getUuid(), Boolean.TRUE); + enrichAuditDetails(request, Boolean.TRUE); } public void enrichPlanConfiguration(PlanConfiguration planConfiguration) { log.info("enriching plan config with generated IDs"); + + // Generate id for plan configuration UUIDEnrichmentUtil.enrichRandomUuid(planConfiguration, "id"); - UUIDEnrichmentUtil.enrichRandomUuid(planConfiguration.getFiles(), "id"); - UUIDEnrichmentUtil.enrichRandomUuid(planConfiguration.getAssumptions(), "id"); - UUIDEnrichmentUtil.enrichRandomUuid(planConfiguration.getOperations(), "id"); - UUIDEnrichmentUtil.enrichRandomUuid(planConfiguration.getResourceMapping(), "id"); - } + // Generate id for files + planConfiguration.getFiles().forEach(file -> UUIDEnrichmentUtil.enrichRandomUuid(file, "id")); + + // Generate id for assumptions + planConfiguration.getAssumptions().forEach(assumption -> UUIDEnrichmentUtil.enrichRandomUuid(assumption, "id")); - public void enrichAuditDetails(PlanConfiguration planConfiguration, String by, Boolean isCreate) { - Long time = System.currentTimeMillis(); - planConfiguration.setAuditDetails(getAuditDetails(by,planConfiguration.getAuditDetails(), isCreate)); + // Generate id for operations + planConfiguration.getOperations().forEach(operation -> UUIDEnrichmentUtil.enrichRandomUuid(operation, "id")); + + // Generate id for resource mappings + planConfiguration.getResourceMapping().forEach(resourceMapping -> UUIDEnrichmentUtil.enrichRandomUuid(resourceMapping, "id")); } - public AuditDetails getAuditDetails(String by, AuditDetails auditDetails, Boolean isCreate) { - Long time = System.currentTimeMillis(); - if (isCreate) - return AuditDetails.builder().createdBy(by).lastModifiedBy(by).createdTime(time).lastModifiedTime(time).build(); - else - return AuditDetails.builder().createdBy(auditDetails.getCreatedBy()).lastModifiedBy(by) - .createdTime(auditDetails.getCreatedTime()).lastModifiedTime(time).build(); + public void enrichAuditDetails(PlanConfigurationRequest request, Boolean isCreate) { + // Enrich audit details for plan configurationqq + PlanConfiguration planConfiguration = request.getPlanConfiguration(); + planConfiguration.setAuditDetails(AuditDetailsEnrichmentUtil + .prepareAuditDetails(planConfiguration.getAuditDetails(), request.getRequestInfo(), isCreate)); } + } diff --git a/health-services/plan-service/src/main/resources/application.properties b/health-services/plan-service/src/main/resources/application.properties index cab8b107f9a..fc7fdc13367 100644 --- a/health-services/plan-service/src/main/resources/application.properties +++ b/health-services/plan-service/src/main/resources/application.properties @@ -7,12 +7,12 @@ app.timezone=UTC #DATABASE CONFIGURATION spring.datasource.driver-class-name=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://localhost:5433/plandb +spring.datasource.url=jdbc:postgresql://localhost:5432/plandb spring.datasource.username=postgres spring.datasource.password=postgres #FLYWAY CONFIGURATION -spring.flyway.url=jdbc:postgresql://localhost:5433/plandb +spring.flyway.url=jdbc:postgresql://localhost:5432/plandb spring.flyway.user=postgres spring.flyway.password=postgres spring.flyway.table=public @@ -54,7 +54,7 @@ egov.localization.search.endpoint=/_search egov.localization.statelevel=true #mdms urls -egov.mdms.host=https://dev.digit.org +egov.mdms.host=https://unified-dev.digit.org egov.mdms.search.endpoint=/egov-mdms-service/v1/_search #Workflow config @@ -63,6 +63,8 @@ egov.workflow.host=https://dev.digit.org egov.workflow.transition.path=/egov-workflow-v2/egov-wf/process/_transition egov.workflow.businessservice.search.path=/egov-workflow-v2/egov-wf/businessservice/_search egov.workflow.processinstance.search.path=/egov-workflow-v2/egov-wf/process/_search +egov.idgen.host=http://localhost:8081/ +egov.idgen.path=egov-idgen/id/_generate # The value of the following field should be changed to service specific name kafka.topics.consumer=service-consumer-topic \ No newline at end of file From 07054e5dc7d73caef25f7251b3b112fe861059e3 Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Thu, 7 Mar 2024 16:50:14 +0530 Subject: [PATCH 17/53] [HLM-5129] Enabled field level validations on plan related POJOs --- health-services/plan-service/pom.xml | 4 ---- .../main/java/digit/service/PlanService.java | 14 +++++++++++++- .../digit/web/controllers/PlanController.java | 3 +++ .../main/java/digit/web/models/Activity.java | 4 +++- .../main/java/digit/web/models/Condition.java | 8 ++++++++ .../java/digit/web/models/MetricDetail.java | 7 +++++++ .../src/main/java/digit/web/models/Plan.java | 11 ++++++++--- .../main/java/digit/web/models/PlanRequest.java | 2 +- .../digit/web/models/PlanSearchCriteria.java | 17 +++++++++++------ .../digit/web/models/PlanSearchRequest.java | 2 +- .../main/java/digit/web/models/Resource.java | 12 ++++++------ .../src/main/java/digit/web/models/Target.java | 10 ++++------ 12 files changed, 65 insertions(+), 29 deletions(-) diff --git a/health-services/plan-service/pom.xml b/health-services/plan-service/pom.xml index 88c0d179a85..d2d34ebd25e 100644 --- a/health-services/plan-service/pom.xml +++ b/health-services/plan-service/pom.xml @@ -40,10 +40,6 @@ org.springframework.boot spring-boot-starter-jdbc - - org.hibernate.validator - hibernate-validator - org.flywaydb flyway-core diff --git a/health-services/plan-service/src/main/java/digit/service/PlanService.java b/health-services/plan-service/src/main/java/digit/service/PlanService.java index 305800ef373..64215e6255b 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanService.java @@ -3,9 +3,11 @@ import digit.repository.PlanRepository; import digit.web.models.PlanRequest; import digit.web.models.PlanResponse; +import digit.web.models.PlanSearchRequest; import org.egov.common.utils.ResponseInfoUtil; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.Collections; @Service @@ -24,18 +26,28 @@ public PlanService(PlanValidator planValidator, PlanEnricher planEnricher, PlanR } public PlanResponse createPlan(PlanRequest body) { - // Validate plan create request planValidator.validatePlanCreate(body); // Enrich plan create request planEnricher.enrichPlanCreate(body); + // Delegate creation request to repository planRepository.create(body); + // Build and return response back to controller return PlanResponse.builder() .responseInfo(ResponseInfoUtil.createResponseInfoFromRequestInfo(body.getRequestInfo(), Boolean.TRUE)) .plan(Collections.singletonList(body.getPlan())) .build(); } + + public PlanResponse searchPlan(PlanSearchRequest body) { + + + return PlanResponse.builder() + .responseInfo(ResponseInfoUtil.createResponseInfoFromRequestInfo(body.getRequestInfo(), Boolean.TRUE)) + .plan(new ArrayList<>()) + .build(); + } } diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java index 69946277d34..d9742177dad 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java @@ -7,11 +7,13 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMapping; +@Validated @Controller @RequestMapping("/plan") public class PlanController { @@ -30,6 +32,7 @@ public ResponseEntity createPost(@Valid @RequestBody PlanRequest b @RequestMapping(value = "/_search", method = RequestMethod.POST) public ResponseEntity searchPost(@Valid @RequestBody PlanSearchRequest body) { + PlanResponse planResponse = planService.searchPlan(body); return ResponseEntity.status(HttpStatus.OK).body(new PlanResponse()); } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Activity.java b/health-services/plan-service/src/main/java/digit/web/models/Activity.java index 6260a5955d9..61fea542a3f 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Activity.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Activity.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; -import java.util.Set; +import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; @@ -27,9 +27,11 @@ public class Activity { @JsonProperty("code") @NotNull + @Size(min = 2, max = 128) private String code = null; @JsonProperty("description") + @Size(max = 2048) private String description = null; @JsonProperty("plannedStartDate") diff --git a/health-services/plan-service/src/main/java/digit/web/models/Condition.java b/health-services/plan-service/src/main/java/digit/web/models/Condition.java index 326443be599..74e50d394b7 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Condition.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Condition.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; import javax.validation.constraints.*; @@ -26,12 +28,18 @@ public class Condition { private String id = null; @JsonProperty("entity") + @NotNull + @Size(min = 2, max = 64) private String entity = null; @JsonProperty("entityProperty") + @NotNull + @Size(min = 2, max = 64) private String entityProperty = null; @JsonProperty("expression") + @NotNull + @Size(min = 3, max = 2048) private String expression = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java b/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java index 6a0989ec15c..ffbe649b727 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java +++ b/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java @@ -1,6 +1,8 @@ package digit.web.models; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -17,12 +19,17 @@ public class MetricDetail { @JsonProperty("value") + @NotNull private BigDecimal metricValue = null; @JsonProperty("comparator") + @NotNull + @Size(min = 1, max = 64) private String metricComparator = null; @JsonProperty("unit") + @NotNull + @Size(min = 1, max = 128) private String metricUnit = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Plan.java b/health-services/plan-service/src/main/java/digit/web/models/Plan.java index dda77614398..41e06bfcdb6 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Plan.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Plan.java @@ -3,10 +3,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import org.egov.common.contract.models.AuditDetails; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; @@ -26,16 +27,20 @@ public class Plan { private String id = null; @JsonProperty("tenantId") + @NotNull + @Size(min = 2, max = 64) private String tenantId = null; @JsonProperty("locality") - @Size(min = 2) + @Size(min = 1, max = 64) private String locality = null; @JsonProperty("executionPlanId") + @Size(min = 64, max = 64) private String executionPlanId = null; @JsonProperty("planConfigurationId") + @Size(min = 64, max = 64) private String planConfigurationId = null; @JsonProperty("additionalDetails") diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanRequest.java index d1a037a3815..cf3fd8bfcc8 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanRequest.java @@ -1,9 +1,9 @@ package digit.web.models; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.Valid; import org.egov.common.contract.request.RequestInfo; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java index cf5a39b486a..f7a32f74f83 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java @@ -1,12 +1,11 @@ package digit.web.models; -import java.util.Objects; +import java.util.Set; + import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; @@ -21,8 +20,12 @@ @NoArgsConstructor @Builder public class PlanSearchCriteria { + + @JsonProperty("ids") + private Set ids = null; + @JsonProperty("tenantId") - @Size(min = 1, max = 100) + @NotNull private String tenantId = null; @JsonProperty("locality") @@ -31,5 +34,7 @@ public class PlanSearchCriteria { @JsonProperty("executionPlanId") private String executionPlanId = null; + @JsonProperty("planConfigurationId") + private String planConfigurationId = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java index 4e231f63bef..05847584439 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchRequest.java @@ -1,9 +1,9 @@ package digit.web.models; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.Valid; import org.egov.common.contract.request.RequestInfo; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; diff --git a/health-services/plan-service/src/main/java/digit/web/models/Resource.java b/health-services/plan-service/src/main/java/digit/web/models/Resource.java index e29a308e373..0b64b3108c1 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Resource.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Resource.java @@ -1,14 +1,10 @@ package digit.web.models; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import io.swagger.v3.oas.annotations.media.Schema; import java.math.BigDecimal; -import java.util.UUID; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; @@ -28,12 +24,16 @@ public class Resource { private String id = null; @JsonProperty("resourceType") + @NotNull + @Size(min = 2, max = 256) private String resourceType = null; @JsonProperty("estimatedNumber") + @NotNull private BigDecimal estimatedNumber = null; @JsonProperty("activityCode") + @Size(min = 2, max = 128) private String activityCode = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Target.java b/health-services/plan-service/src/main/java/digit/web/models/Target.java index 4a9cd7d1fa8..ad8bbfa5173 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Target.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Target.java @@ -1,13 +1,9 @@ package digit.web.models; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import io.swagger.v3.oas.annotations.media.Schema; -import java.util.UUID; +import jakarta.validation.Valid; +import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; @@ -31,9 +27,11 @@ public class Target { private String metric = null; @JsonProperty("metricDetail") + @Valid private MetricDetail metricDetail = null; @JsonProperty("activityCode") + @Size(min = 2, max = 128) private String activityCode = null; } From 242af62739f8a60d297489068b9787381ebd5ed3 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 7 Mar 2024 18:17:55 +0530 Subject: [PATCH 18/53] HLM-5184 modifying validations --- .../main/java/digit/web/models/Assumption.java | 10 +++++----- .../src/main/java/digit/web/models/File.java | 11 +++++------ .../main/java/digit/web/models/Operation.java | 17 +++++++++-------- .../digit/web/models/PlanConfiguration.java | 12 ++++++++---- .../java/digit/web/models/ResourceMapping.java | 14 ++++++++------ 5 files changed, 35 insertions(+), 29 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java index 3d9b0f3cb49..b8c6e915351 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java @@ -2,12 +2,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.Valid; import java.math.BigDecimal; -import java.util.UUID; -import org.egov.common.contract.models.AuditDetails; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; @@ -24,11 +23,12 @@ public class Assumption { @JsonProperty("id") @Valid + @Size(min = 2, max = 64) private String id = null; @JsonProperty("key") @NotNull - @Size(min = 1, max = 32) + @Size(min = 1, max = 256) private String key = null; @JsonProperty("value") diff --git a/health-services/plan-service/src/main/java/digit/web/models/File.java b/health-services/plan-service/src/main/java/digit/web/models/File.java index a9cee864e70..a4bd3dd030b 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/File.java +++ b/health-services/plan-service/src/main/java/digit/web/models/File.java @@ -1,15 +1,12 @@ package digit.web.models; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; -import io.swagger.v3.oas.annotations.media.Schema; -import java.util.UUID; -import org.egov.common.contract.models.AuditDetails; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; -import javax.validation.constraints.*; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; @@ -26,15 +23,17 @@ public class File { @JsonProperty("id") @Valid + @Size(min = 2, max = 64) private String id = null; @JsonProperty("filestoreId") @NotNull - @Size(min = 1, max = 32) + @Size(min = 1, max = 128) private String filestoreId = null; @JsonProperty("inputFileType") @NotNull + @Size(min = 2, max = 64) private InputFileTypeEnum inputFileType = null; /** diff --git a/health-services/plan-service/src/main/java/digit/web/models/Operation.java b/health-services/plan-service/src/main/java/digit/web/models/Operation.java index 90a12e200ac..39098d5f0d4 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Operation.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Operation.java @@ -4,14 +4,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; -import io.swagger.v3.oas.annotations.media.Schema; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.UUID; -import org.egov.common.contract.models.AuditDetails; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; -import javax.validation.constraints.*; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; @@ -28,22 +24,27 @@ public class Operation { @JsonProperty("id") @Valid + @Size(min = 2, max = 64) private String id = null; @JsonProperty("input") @NotNull - @Size(min = 1, max = 32) + @Size(min = 1, max = 256) private String input = null; @JsonProperty("operator") @NotNull + @Size(min = 2, max = 64) private OperatorEnum operator = null; @JsonProperty("assumptionValue") + @NotNull + @Size(min = 2, max = 256) private String assumptionValue = null; @JsonProperty("output") - @Size(min = 1, max = 32) + @NotNull + @Size(min = 1, max = 64) private String output = null; /** diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java index e29be80616f..802f62aaef8 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java @@ -3,11 +3,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.ArrayList; import java.util.List; -import java.util.UUID; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import org.egov.common.contract.models.AuditDetails; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; @@ -24,18 +24,22 @@ public class PlanConfiguration { @JsonProperty("id") @Valid + @Size(min = 2, max = 64) private String id = null; @JsonProperty("tenantId") @NotNull + @Size(min = 2, max = 64) private String tenantId = null; @JsonProperty("name") @NotNull - @Size(min = 2) + @Size(min = 2, max = 128) private String name = null; @JsonProperty("executionPlanId") + @NotNull + @Size(min = 2, max = 64) private String executionPlanId = null; @JsonProperty("files") diff --git a/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java index 278b25e7d07..7f561b7e50b 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java +++ b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java @@ -1,13 +1,11 @@ package digit.web.models; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import io.swagger.v3.oas.annotations.media.Schema; -import org.egov.common.contract.models.AuditDetails; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; @@ -27,9 +25,13 @@ public class ResourceMapping { private String id = null; @JsonProperty("mappedFrom") + @NotNull + @Size(min = 2, max = 256) private String mappedFrom = null; @JsonProperty("mappedTo") + @NotNull + @Size(min = 2, max = 256) private String mappedTo = null; } From c44db8735abcf23c1d15618b6a84bd094762d918 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Fri, 8 Mar 2024 10:38:02 +0530 Subject: [PATCH 19/53] HLM-5184 cleaned up javax imports --- .../java/digit/web/controllers/PlanConfigController.java | 2 +- .../src/main/java/digit/web/models/Condition.java | 5 ----- .../plan-service/src/main/java/digit/web/models/File.java | 2 +- .../src/main/java/digit/web/models/Operation.java | 2 +- .../java/digit/web/models/PlanConfigurationRequest.java | 2 +- .../java/digit/web/models/PlanConfigurationResponse.java | 2 +- .../digit/web/models/PlanConfigurationSearchCriteria.java | 6 +----- .../digit/web/models/PlanConfigurationSearchRequest.java | 2 +- .../src/main/java/digit/web/models/PlanEditRequest.java | 2 +- .../src/main/java/digit/web/models/PlanResponse.java | 3 +-- 10 files changed, 9 insertions(+), 19 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java index 452c6146eb5..944b1bae745 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java @@ -5,7 +5,7 @@ import digit.web.models.PlanConfigurationRequest; import digit.web.models.PlanConfigurationResponse; import digit.web.models.PlanConfigurationSearchRequest; -import javax.validation.Valid; +import jakarta.validation.Valid; import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; diff --git a/health-services/plan-service/src/main/java/digit/web/models/Condition.java b/health-services/plan-service/src/main/java/digit/web/models/Condition.java index 74e50d394b7..a30525b2f45 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Condition.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Condition.java @@ -1,14 +1,9 @@ package digit.web.models; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; diff --git a/health-services/plan-service/src/main/java/digit/web/models/File.java b/health-services/plan-service/src/main/java/digit/web/models/File.java index a4bd3dd030b..a2a5865721a 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/File.java +++ b/health-services/plan-service/src/main/java/digit/web/models/File.java @@ -6,7 +6,7 @@ import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; +import jakarta.validation.Valid; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; diff --git a/health-services/plan-service/src/main/java/digit/web/models/Operation.java b/health-services/plan-service/src/main/java/digit/web/models/Operation.java index 39098d5f0d4..25f1f3ef10e 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Operation.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Operation.java @@ -7,7 +7,7 @@ import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; +import jakarta.validation.Valid; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java index 1f428231b59..4636259bde7 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationRequest.java @@ -4,7 +4,7 @@ import org.egov.common.contract.request.RequestInfo; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; +import jakarta.validation.Valid; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java index 6948daa8cca..2a5277e9e3c 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java @@ -5,7 +5,7 @@ import java.util.List; import org.egov.common.contract.response.ResponseInfo; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; +import jakarta.validation.Valid; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java index da979d641c8..f0173e47284 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java @@ -1,12 +1,8 @@ package digit.web.models; -import java.util.Objects; +import jakarta.validation.constraints.Size; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import io.swagger.v3.oas.annotations.media.Schema; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java index 6f9aecc4476..11874e2a600 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchRequest.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.egov.common.contract.request.RequestInfo; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; +import jakarta.validation.Valid; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java index 9e0ec4f1d1c..6a41cebcd48 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.egov.common.contract.request.RequestInfo; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; +import jakarta.validation.Valid; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java b/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java index 61b8f2b652f..bf08ba0059c 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanResponse.java @@ -1,11 +1,10 @@ package digit.web.models; import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.ArrayList; import java.util.List; import org.egov.common.contract.response.ResponseInfo; import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; +import jakarta.validation.Valid; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; From c7dcc1ec285d72381ea781a0adc58df8bea29339 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Fri, 8 Mar 2024 10:54:39 +0530 Subject: [PATCH 20/53] HLM-5143 adding plan-service to build config --- build/build-config.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build/build-config.yml b/build/build-config.yml index 10f839d51e8..b54023b9eda 100644 --- a/build/build-config.yml +++ b/build/build-config.yml @@ -168,10 +168,10 @@ config: dockerfile: "build/maven/Dockerfile" - work-dir: "core-services/egov-hrms/src/main/resources/db" image-name: "health-hrms-db" - - name: "builds/health-campaign-services/health-services/facility" + - name: "builds/health-campaign-services/health-services/plan-service" build: - - work-dir: "health-services/facility" - image-name: "facility" + - work-dir: "health-services/plan-service" + image-name: "plan-service" dockerfile: "build/maven/Dockerfile" - - work-dir: "health-services/facility/src/main/resources/db" - image-name: "facility-db" + - work-dir: "health-services/plan-service/src/main/resources/db" + image-name: "plan-service-db" From b2668c44f7e0c48839985f5870c20f78c378b323 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Fri, 8 Mar 2024 11:38:01 +0530 Subject: [PATCH 21/53] HLM-5143 adding changes for validation --- .../src/main/java/digit/config/ServiceConstants.java | 4 ++-- .../digit/service/validator/PlanConfigurationValidator.java | 5 +++-- .../plan-service/src/main/java/digit/web/models/File.java | 1 - .../src/main/java/digit/web/models/Operation.java | 1 - 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index 83ec4d5ced3..db69834de03 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -55,9 +55,9 @@ public class ServiceConstants { public static final String ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_CODE = "ASSUMPTION_KEY_NOT_FOUND_IN_MDMS"; public static final String ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_MESSAGE = "Assumption Key is not present in MDMS"; - public static final String MDMS_PLAN_ASSUMPTION_MODULE_NAME = ""; + public static final String MDMS_PLAN_ASSUMPTION_MODULE_NAME = "hcm-microplanning"; - public static final String MDMS_MASTER_ASSUMPTION = ""; + public static final String MDMS_MASTER_ASSUMPTION = "Assumptions"; } diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index 8d7493df5df..1dc0211e893 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -30,7 +30,7 @@ public class PlanConfigurationValidator { MdmsUtil mdmsUtil; public void validateCreate(PlanConfigurationRequest request) { -// validateAssumptionKeyAgainstMDMS(request); + validateAssumptionKeyAgainstMDMS(request); validateAssumptionValue(request.getPlanConfiguration()); } @@ -52,10 +52,11 @@ public void validateAssumptionKeyAgainstMDMS(PlanConfigurationRequest request) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); String rootTenantId = planConfiguration.getTenantId().split("\\.")[0]; Object mdmsData = mdmsUtil.fetchMdmsData(request.getRequestInfo(), rootTenantId, MDMS_PLAN_ASSUMPTION_MODULE_NAME, Collections.singletonList(MDMS_MASTER_ASSUMPTION)); - final String jsonPathForAssumption = "$.MdmsRes." + MDMS_PLAN_ASSUMPTION_MODULE_NAME + "." + MDMS_MASTER_ASSUMPTION + ".*"; + final String jsonPathForAssumption = "$." + MDMS_PLAN_ASSUMPTION_MODULE_NAME + "." + MDMS_MASTER_ASSUMPTION + ".*.code"; List assumptionListFromMDMS = null; try { + log.info(jsonPathForAssumption); assumptionListFromMDMS = JsonPath.read(mdmsData, jsonPathForAssumption); } catch (Exception e) { log.error(e.getMessage()); diff --git a/health-services/plan-service/src/main/java/digit/web/models/File.java b/health-services/plan-service/src/main/java/digit/web/models/File.java index a2a5865721a..9d06c9d866f 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/File.java +++ b/health-services/plan-service/src/main/java/digit/web/models/File.java @@ -33,7 +33,6 @@ public class File { @JsonProperty("inputFileType") @NotNull - @Size(min = 2, max = 64) private InputFileTypeEnum inputFileType = null; /** diff --git a/health-services/plan-service/src/main/java/digit/web/models/Operation.java b/health-services/plan-service/src/main/java/digit/web/models/Operation.java index 25f1f3ef10e..bbeb688c0d4 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Operation.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Operation.java @@ -34,7 +34,6 @@ public class Operation { @JsonProperty("operator") @NotNull - @Size(min = 2, max = 64) private OperatorEnum operator = null; @JsonProperty("assumptionValue") From 8aca49a245fa2785b264b4a6940297ad665dee66 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Mon, 11 Mar 2024 12:44:35 +0530 Subject: [PATCH 22/53] HLM-5143 adding springboot maven plugin related changes in pom for plan-service --- health-services/plan-service/pom.xml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/health-services/plan-service/pom.xml b/health-services/plan-service/pom.xml index d2d34ebd25e..ce6a2dff717 100644 --- a/health-services/plan-service/pom.xml +++ b/health-services/plan-service/pom.xml @@ -21,13 +21,6 @@ org.springframework.boot spring-boot-maven-plugin - - - - repackage - - - @@ -96,11 +89,6 @@ junit test - - junit - junit - test - From 27acced2833cf33b71e98c18c99d3506466b7f47 Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Mon, 11 Mar 2024 16:48:39 +0530 Subject: [PATCH 23/53] [HLM-5187] Added plan enrichments and search endpoint --- .../main/java/digit/config/Configuration.java | 12 +- .../java/digit/config/MainConfiguration.java | 15 +- .../java/digit/config/ServiceConstants.java | 3 + .../java/digit/repository/PlanRepository.java | 5 +- .../repository/impl/PlanRepositoryImpl.java | 44 +++- .../querybuilder/PlanQueryBuilder.java | 115 ++++++++++ .../repository/rowmapper/PlanRowMapper.java | 197 ++++++++++++++++++ .../main/java/digit/service/PlanService.java | 8 +- .../src/main/java/digit/util/QueryUtil.java | 126 +++++++++++ .../digit/web/controllers/PlanController.java | 2 +- .../main/java/digit/web/models/Activity.java | 1 + .../digit/web/models/PlanSearchCriteria.java | 6 + .../src/main/resources/application.properties | 12 +- 13 files changed, 527 insertions(+), 19 deletions(-) create mode 100644 health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java create mode 100644 health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java create mode 100644 health-services/plan-service/src/main/java/digit/util/QueryUtil.java diff --git a/health-services/plan-service/src/main/java/digit/config/Configuration.java b/health-services/plan-service/src/main/java/digit/config/Configuration.java index 313ada777c0..cced66a6137 100644 --- a/health-services/plan-service/src/main/java/digit/config/Configuration.java +++ b/health-services/plan-service/src/main/java/digit/config/Configuration.java @@ -21,7 +21,6 @@ @Getter public class Configuration { - //Workflow Config @Value("${egov.workflow.host}") private String wfHost; @@ -34,19 +33,22 @@ public class Configuration { @Value("${egov.workflow.processinstance.search.path}") private String wfProcessInstanceSearchPath; - - //MDMS @Value("${egov.mdms.host}") private String mdmsHost; @Value("${egov.mdms.search.endpoint}") private String mdmsEndPoint; - - //Persister Topic @Value("${plan.configuration.create.topic}") private String planConfigCreateTopic; @Value("${plan.configuration.update.topic}") private String planConfigUpdateTopic; + + @Value("${plan.default.offset}") + private Integer defaultOffset; + + @Value("${plan.default.limit}") + private Integer defaultLimit; + } diff --git a/health-services/plan-service/src/main/java/digit/config/MainConfiguration.java b/health-services/plan-service/src/main/java/digit/config/MainConfiguration.java index a0f8e0ee2af..ea9816c9be0 100644 --- a/health-services/plan-service/src/main/java/digit/config/MainConfiguration.java +++ b/health-services/plan-service/src/main/java/digit/config/MainConfiguration.java @@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import org.egov.tracer.config.TracerConfiguration; +import org.springframework.jdbc.core.SingleColumnRowMapper; @Import({TracerConfiguration.class}) @@ -26,14 +27,20 @@ public void initialize() { @Bean public ObjectMapper objectMapper(){ - return new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).setTimeZone(TimeZone.getTimeZone(timeZone)); + return new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).setTimeZone(TimeZone.getTimeZone(timeZone)); } @Bean @Autowired public MappingJackson2HttpMessageConverter jacksonConverter(ObjectMapper objectMapper) { - MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); - converter.setObjectMapper(objectMapper); - return converter; + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); + converter.setObjectMapper(objectMapper); + return converter; } + + @Bean + public SingleColumnRowMapper singleColumnRowMapper() { + return new SingleColumnRowMapper<>(String.class); + } + } \ No newline at end of file diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index db69834de03..aeb4ec21764 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -59,5 +59,8 @@ public class ServiceConstants { public static final String MDMS_MASTER_ASSUMPTION = "Assumptions"; + public static final String DOT_SEPARATOR = "."; + + public static final String DOT_REGEX = "\\."; } diff --git a/health-services/plan-service/src/main/java/digit/repository/PlanRepository.java b/health-services/plan-service/src/main/java/digit/repository/PlanRepository.java index 423129b9174..eb76b357701 100644 --- a/health-services/plan-service/src/main/java/digit/repository/PlanRepository.java +++ b/health-services/plan-service/src/main/java/digit/repository/PlanRepository.java @@ -1,12 +1,15 @@ package digit.repository; +import digit.web.models.Plan; import digit.web.models.PlanRequest; import digit.web.models.PlanSearchCriteria; +import java.util.List; + public interface PlanRepository { public void create(PlanRequest planRequest); - public void search(PlanSearchCriteria planSearchCriteria); + public List search(PlanSearchCriteria planSearchCriteria); public void update(PlanRequest planRequest); diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java index 0f3df939455..aaf327a2bbf 100644 --- a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java @@ -2,17 +2,37 @@ import digit.kafka.Producer; import digit.repository.PlanRepository; +import digit.repository.querybuilder.PlanQueryBuilder; +import digit.repository.rowmapper.PlanRowMapper; +import digit.web.models.Plan; import digit.web.models.PlanRequest; import digit.web.models.PlanSearchCriteria; +import lombok.extern.slf4j.Slf4j; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.SingleColumnRowMapper; import org.springframework.stereotype.Repository; +import java.util.ArrayList; +import java.util.List; + +@Slf4j @Repository public class PlanRepositoryImpl implements PlanRepository { private Producer producer; - public PlanRepositoryImpl(Producer producer) { + private PlanQueryBuilder planQueryBuilder; + + private PlanRowMapper planRowMapper; + + private JdbcTemplate jdbcTemplate; + + public PlanRepositoryImpl(Producer producer, PlanQueryBuilder planQueryBuilder, PlanRowMapper planRowMapper, + JdbcTemplate jdbcTemplate) { this.producer = producer; + this.planQueryBuilder = planQueryBuilder; + this.planRowMapper = planRowMapper; + this.jdbcTemplate = jdbcTemplate; } @Override @@ -21,12 +41,32 @@ public void create(PlanRequest planRequest) { } @Override - public void search(PlanSearchCriteria planSearchCriteria) { + public List search(PlanSearchCriteria planSearchCriteria) { + List planIds = queryDatabaseForPlanIds(planSearchCriteria); + log.info("Plan ids: " + planIds); + + List plans = searchPlanByIds(planIds); + return plans; } @Override public void update(PlanRequest planRequest) { producer.push("update-plan", planRequest); } + + private List queryDatabaseForPlanIds(PlanSearchCriteria planSearchCriteria) { + List preparedStmtList = new ArrayList<>(); + String query = planQueryBuilder.getPlanSearchQuery(planSearchCriteria, preparedStmtList); + log.info("Plan search query: " + query); + return jdbcTemplate.query(query, new SingleColumnRowMapper<>(String.class), preparedStmtList.toArray()); + } + + private List searchPlanByIds(List planIds) { + List preparedStmtList = new ArrayList<>(); + String query = planQueryBuilder.getPlanQuery(planIds, preparedStmtList); + log.info("Plan query: " + query); + return jdbcTemplate.query(query, planRowMapper, preparedStmtList.toArray()); + } + } diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java new file mode 100644 index 00000000000..1b0adb59213 --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java @@ -0,0 +1,115 @@ +package digit.repository.querybuilder; + +import digit.config.Configuration; +import digit.util.QueryUtil; +import digit.web.models.PlanSearchCriteria; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; +import java.util.LinkedHashSet; +import java.util.List; + +@Component +public class PlanQueryBuilder { + + private Configuration config; + + public PlanQueryBuilder(Configuration config) { + this.config = config; + } + + private static final String PLAN_SEARCH_BASE_QUERY = "SELECT id FROM plan "; + + private static final String PLAN_QUERY = "SELECT plan.id as plan_id, plan.tenant_id as plan_tenant_id, plan.locality as plan_locality, plan.execution_plan_id as plan_execution_plan_id, plan.plan_configuration_id as plan_plan_configuration_id, plan.additional_details as plan_additional_details, plan.created_by as plan_created_by, plan.created_time as plan_created_time, plan.last_modified_by as plan_last_modified_by, plan.last_modified_time as plan_last_modified_time,\n" + + "\t plan_activity.id as plan_activity_id, plan_activity.code as plan_activity_code, plan_activity.description as plan_activity_description, plan_activity.planned_start_date as plan_activity_planned_start_date, plan_activity.planned_end_date as plan_activity_planned_end_date, plan_activity.dependencies as plan_activity_dependencies, plan_activity.plan_id as plan_activity_plan_id, plan_activity.created_by as plan_activity_created_by, plan_activity.created_time as plan_activity_created_time, plan_activity.last_modified_by as plan_activity_last_modified_by, plan_activity.last_modified_time as plan_activity_last_modified_time,\n" + + "\t plan_activity_condition.id as plan_activity_condition_id, plan_activity_condition.entity as plan_activity_condition_entity, plan_activity_condition.entity_property as plan_activity_condition_entity_property, plan_activity_condition.expression as plan_activity_condition_expression, plan_activity_condition.activity_id as plan_activity_condition_activity_id, plan_activity_condition.is_active as plan_activity_condition_is_active, plan_activity_condition.created_by as plan_activity_condition_created_by, plan_activity_condition.created_time as plan_activity_condition_created_time, plan_activity_condition.last_modified_by as plan_activity_condition_last_modified_by, plan_activity_condition.last_modified_time as plan_activity_condition_last_modified_time,\n" + + "\t plan_resource.id as plan_resource_id, plan_resource.resource_type as plan_resource_resource_type, plan_resource.estimated_number as plan_resource_estimated_number, plan_resource.plan_id as plan_resource_plan_id, plan_resource.activity_code as plan_resource_activity_code, plan_resource.created_by as plan_resource_created_by, plan_resource.created_time as plan_resource_created_time, plan_resource.last_modified_by as plan_resource_last_modified_by, plan_resource.last_modified_time as plan_resource_last_modified_time,\n" + + "\t plan_target.id as plan_target_id, plan_target.metric as plan_target_metric, plan_target.metric_value as plan_target_metric_value, plan_target.metric_comparator as plan_target_metric_comparator, plan_target.metric_unit as plan_target_metric_unit, plan_target.plan_id as plan_target_plan_id, plan_target.activity_code as plan_target_activity_code, plan_target.created_by as plan_target_created_by, plan_target.created_time as plan_target_created_time, plan_target.last_modified_by as plan_target_last_modified_by, plan_target.last_modified_time as plan_target_last_modified_time\n" + + "\t FROM plan \n" + + "\t LEFT JOIN plan_activity ON plan.id = plan_activity.plan_id\n" + + "\t LEFT JOIN plan_activity_condition ON plan_activity.id = plan_activity_condition.activity_id\n" + + "\t LEFT JOIN plan_resource ON plan.id = plan_resource.plan_id\n" + + "\t LEFT JOIN plan_target ON plan.id = plan_target.plan_id"; + + private static final String PLAN_SEARCH_QUERY_ORDER_BY_CLAUSE = " order by plan.last_modified_time desc "; + + public String getPlanQuery(List ids, List preparedStmtList) { + return buildPlanQuery(ids, preparedStmtList); + } + + private String buildPlanQuery(List ids, List preparedStmtList) { + StringBuilder builder = new StringBuilder(PLAN_QUERY); + + if (!CollectionUtils.isEmpty(ids)) { + QueryUtil.addClauseIfRequired(builder, preparedStmtList); + builder.append(" plan.id IN ( ").append(QueryUtil.createQuery(ids.size())).append(" )"); + QueryUtil.addToPreparedStatement(preparedStmtList, new LinkedHashSet<>(ids)); + } + + return builder.toString(); + } + + public String getPlanSearchQuery(PlanSearchCriteria planSearchCriteria, List preparedStmtList) { + String query = buildPlanSearchQuery(planSearchCriteria, preparedStmtList); + query = QueryUtil.addOrderByClause(query, PLAN_SEARCH_QUERY_ORDER_BY_CLAUSE); + query = getPaginatedQuery(query, planSearchCriteria, preparedStmtList); + return query; + } + + /** + * Method to build query dynamically based on the criteria passed to the method + * @param planSearchCriteria + * @param preparedStmtList + * @return + */ + private String buildPlanSearchQuery(PlanSearchCriteria planSearchCriteria, List preparedStmtList) { + StringBuilder builder = new StringBuilder(PLAN_SEARCH_BASE_QUERY); + + if (!ObjectUtils.isEmpty(planSearchCriteria.getTenantId())) { + QueryUtil.addClauseIfRequired(builder, preparedStmtList); + builder.append(" tenant_id = ? "); + preparedStmtList.add(planSearchCriteria.getTenantId()); + } + + if (!CollectionUtils.isEmpty(planSearchCriteria.getIds())) { + QueryUtil.addClauseIfRequired(builder, preparedStmtList); + builder.append(" id IN ( ").append(QueryUtil.createQuery(planSearchCriteria.getIds().size())).append(" )"); + QueryUtil.addToPreparedStatement(preparedStmtList, planSearchCriteria.getIds()); + } + + if (!ObjectUtils.isEmpty(planSearchCriteria.getLocality())) { + QueryUtil.addClauseIfRequired(builder, preparedStmtList); + builder.append(" locality = ? "); + preparedStmtList.add(planSearchCriteria.getLocality()); + } + + if (!ObjectUtils.isEmpty(planSearchCriteria.getExecutionPlanId())) { + QueryUtil.addClauseIfRequired(builder, preparedStmtList); + builder.append(" execution_plan_id = ? "); + preparedStmtList.add(planSearchCriteria.getExecutionPlanId()); + } + + if (!ObjectUtils.isEmpty(planSearchCriteria.getPlanConfigurationId())) { + QueryUtil.addClauseIfRequired(builder, preparedStmtList); + builder.append(" plan_configuration_id = ? "); + preparedStmtList.add(planSearchCriteria.getPlanConfigurationId()); + } + + return builder.toString(); + } + + private String getPaginatedQuery(String query, PlanSearchCriteria planSearchCriteria, List preparedStmtList) { + StringBuilder paginatedQuery = new StringBuilder(query); + + // Append offset + paginatedQuery.append(" OFFSET ? "); + preparedStmtList.add(ObjectUtils.isEmpty(planSearchCriteria.getOffset()) ? config.getDefaultOffset() : planSearchCriteria.getOffset()); + + // Append limit + paginatedQuery.append(" LIMIT ? "); + preparedStmtList.add(ObjectUtils.isEmpty(planSearchCriteria.getLimit()) ? config.getDefaultLimit() : planSearchCriteria.getLimit()); + + return paginatedQuery.toString(); + } + +} diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java new file mode 100644 index 00000000000..64cbc2a59a7 --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java @@ -0,0 +1,197 @@ +package digit.repository.rowmapper; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import digit.web.models.*; +import org.egov.common.contract.models.AuditDetails; +import org.egov.tracer.model.CustomException; +import org.postgresql.util.PGobject; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; + +import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; + +@Component +public class PlanRowMapper implements ResultSetExtractor> { + + private ObjectMapper objectMapper; + + public PlanRowMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @Override + public List extractData(ResultSet rs) throws SQLException, DataAccessException { + Map planMap = new LinkedHashMap<>(); + + // Traverse through result set and create plan objects + while(rs.next()) { + String planId = rs.getString("plan_id"); + + Plan planEntry = planMap.get(planId); + + if(ObjectUtils.isEmpty(planEntry)) { + planEntry = new Plan(); + + // Prepare audit details + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("plan_created_by")) + .createdTime(rs.getLong("plan_created_time")) + .lastModifiedBy(rs.getString("plan_last_modified_by")) + .lastModifiedTime(rs.getLong("plan_last_modified_time")) + .build(); + + // Prepare plan object + planEntry.setId(planId); + planEntry.setTenantId(rs.getString("plan_tenant_id")); + planEntry.setLocality(rs.getString("plan_locality")); + planEntry.setExecutionPlanId(rs.getString("plan_execution_plan_id")); + planEntry.setPlanConfigurationId(rs.getString("plan_plan_configuration_id")); + planEntry.setAdditionalDetails(getAdditionalDetail((PGobject) rs.getObject("plan_additional_details"))); + planEntry.setAuditDetails(auditDetails); + + } + + addActivities(rs, planEntry); + addResources(rs, planEntry); + addTargets(rs, planEntry); + planMap.put(planId, planEntry); + } + + return new ArrayList<>(planMap.values()); + } + + private void addActivities(ResultSet rs, Plan plan) throws SQLException, DataAccessException { + String dependencies = rs.getString("plan_activity_dependencies"); + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("plan_activity_created_by")) + .createdTime(rs.getLong("plan_activity_created_time")) + .lastModifiedBy(rs.getString("plan_activity_last_modified_by")) + .lastModifiedTime(rs.getLong("plan_activity_last_modified_time")) + .build(); + + Activity activity = Activity.builder() + .id(rs.getString("plan_activity_id")) + .code(rs.getString("plan_activity_code")) + .description(rs.getString("plan_activity_description")) + .plannedStartDate(rs.getLong("plan_activity_planned_start_date")) + .plannedEndDate(rs.getLong("plan_activity_planned_end_date")) + .dependencies(ObjectUtils.isEmpty(dependencies) ? new ArrayList<>() : Arrays.asList(rs.getString("plan_activity_dependencies").split(","))) + .build(); + + addActivityConditions(rs, activity); + + if (CollectionUtils.isEmpty(plan.getActivities())) { + List activityList = new ArrayList<>(); + activityList.add(activity); + plan.setActivities(activityList); + } else { + plan.getActivities().add(activity); + } + + } + + private void addActivityConditions(ResultSet rs, Activity activity) throws SQLException, DataAccessException { + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("plan_activity_condition_created_by")) + .createdTime(rs.getLong("plan_activity_condition_created_time")) + .lastModifiedBy(rs.getString("plan_activity_condition_last_modified_by")) + .lastModifiedTime(rs.getLong("plan_activity_condition_last_modified_time")) + .build(); + + Condition condition = Condition.builder() + .id(rs.getString("plan_activity_condition_id")) + .entity(rs.getString("plan_activity_condition_entity")) + .entityProperty(rs.getString("plan_activity_condition_entity_property")) + .expression(rs.getString("plan_activity_condition_expression")) + .build(); + + if(CollectionUtils.isEmpty(activity.getConditions())){ + List conditionList = new ArrayList<>(); + conditionList.add(condition); + activity.setConditions(conditionList); + } else { + activity.getConditions().add(condition); + } + + } + + private void addResources(ResultSet rs, Plan planEntry) throws SQLException, DataAccessException { + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("plan_resource_created_by")) + .createdTime(rs.getLong("plan_resource_created_time")) + .lastModifiedBy(rs.getString("plan_resource_last_modified_by")) + .lastModifiedTime(rs.getLong("plan_resource_last_modified_time")) + .build(); + + Resource resource = Resource.builder() + .id(rs.getString("plan_resource_id")) + .resourceType(rs.getString("plan_resource_resource_type")) + .estimatedNumber(rs.getBigDecimal("plan_resource_estimated_number")) + .activityCode(rs.getString("plan_resource_activity_code")) + .build(); + + if (CollectionUtils.isEmpty(planEntry.getResources())) { + List resourceList = new ArrayList<>(); + resourceList.add(resource); + planEntry.setResources(resourceList); + } else { + planEntry.getResources().add(resource); + } + + } + + private void addTargets(ResultSet rs, Plan planEntry) throws SQLException, DataAccessException { + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("plan_target_created_by")) + .createdTime(rs.getLong("plan_target_created_time")) + .lastModifiedBy(rs.getString("plan_target_last_modified_by")) + .lastModifiedTime(rs.getLong("plan_target_last_modified_time")) + .build(); + + MetricDetail metricDetail = MetricDetail.builder() + .metricValue(rs.getBigDecimal("plan_target_metric_value")) + .metricComparator(rs.getString("plan_target_metric_comparator")) + .metricUnit(rs.getString("plan_target_metric_unit")) + .build(); + + Target target = Target.builder() + .id(rs.getString("plan_target_id")) + .metric(rs.getString("plan_target_metric")) + .metricDetail(metricDetail) + .activityCode(rs.getString("plan_target_activity_code")) + .build(); + + if (CollectionUtils.isEmpty(planEntry.getTargets())) { + List targetList = new ArrayList<>(); + targetList.add(target); + planEntry.setTargets(targetList); + } else { + planEntry.getTargets().add(target); + } + + } + + private JsonNode getAdditionalDetail(PGobject pGobject){ + JsonNode additionalDetail = null; + + try { + if(ObjectUtils.isEmpty(pGobject)){ + additionalDetail = objectMapper.readTree(pGobject.getValue()); + } + } + catch (IOException e){ + throw new CustomException("PARSING_ERROR", "Failed to parse additionalDetails object"); + } + + return additionalDetail; + } + +} diff --git a/health-services/plan-service/src/main/java/digit/service/PlanService.java b/health-services/plan-service/src/main/java/digit/service/PlanService.java index 64215e6255b..976ef2e05a2 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanService.java @@ -1,6 +1,7 @@ package digit.service; import digit.repository.PlanRepository; +import digit.web.models.Plan; import digit.web.models.PlanRequest; import digit.web.models.PlanResponse; import digit.web.models.PlanSearchRequest; @@ -9,6 +10,7 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.List; @Service public class PlanService { @@ -43,11 +45,13 @@ public PlanResponse createPlan(PlanRequest body) { } public PlanResponse searchPlan(PlanSearchRequest body) { - + // Delegate search request to repository + List planList = planRepository.search(body.getPlanSearchCriteria()); + // Build and return response back to controller return PlanResponse.builder() .responseInfo(ResponseInfoUtil.createResponseInfoFromRequestInfo(body.getRequestInfo(), Boolean.TRUE)) - .plan(new ArrayList<>()) + .plan(planList) .build(); } } diff --git a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java new file mode 100644 index 00000000000..84817b60870 --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java @@ -0,0 +1,126 @@ +package digit.util; + +import com.google.gson.Gson; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.IntStream; + +import static digit.config.ServiceConstants.DOT_REGEX; +import static digit.config.ServiceConstants.DOT_SEPARATOR; + + +public class QueryUtil { + + private QueryUtil(){} + + private static final Gson gson = new Gson(); + + /** + * This method aids in adding "WHERE" clause and "AND" condition depending on preparedStatementList i.e., + * if preparedStatementList is empty, it will understand that it is the first clause being added so it + * will add "WHERE" to the query and otherwise it will + * @param query + * @param preparedStmtList + */ + public static void addClauseIfRequired(StringBuilder query, List preparedStmtList){ + if(preparedStmtList.isEmpty()){ + query.append(" WHERE "); + }else{ + query.append(" AND "); + } + } + + /** + * This method returns a string with placeholders equal to the number of values that need to be put inside + * "IN" clause + * @param size + * @return + */ + public static String createQuery(Integer size) { + StringBuilder builder = new StringBuilder(); + + IntStream.range(0, size).forEach(i -> { + builder.append(" ?"); + if (i != size - 1) + builder.append(","); + }); + + return builder.toString(); + } + + /** + * This method adds a set of String values into preparedStatementList + * @param preparedStmtList + * @param ids + */ + public static void addToPreparedStatement(List preparedStmtList, Set ids) { + ids.forEach(id -> { + preparedStmtList.add(id); + }); + } + + /** + * This method appends order by clause to the query + * @param query + * @param orderByClause + * @return + */ + public static String addOrderByClause(String query, String orderByClause){ + return query + orderByClause; + } + + /** + * This method prepares partial json string from the filter map to query on jsonb column + * @param filterMap + * @return + */ + public static String preparePartialJsonStringFromFilterMap(Map filterMap) { + Map queryMap = new HashMap<>(); + + filterMap.keySet().forEach(key -> { + if(key.contains(DOT_SEPARATOR)){ + String[] keyArray = key.split(DOT_REGEX); + Map nestedQueryMap = new HashMap<>(); + prepareNestedQueryMap(0, keyArray, nestedQueryMap, filterMap.get(key)); + queryMap.put(keyArray[0], nestedQueryMap.get(keyArray[0])); + } else{ + queryMap.put(key, filterMap.get(key)); + } + }); + + String partialJsonQueryString = gson.toJson(queryMap); + + return partialJsonQueryString; + } + + /** + * Tail recursive method to prepare n-level nested partial json for queries on nested data in + * master data. For e.g. , if the key is in the format a.b.c, it will construct a nested json + * object of the form - {"a":{"b":{"c": "value"}}} + * @param index + * @param nestedKeyArray + * @param currentQueryMap + * @param value + */ + private static void prepareNestedQueryMap(int index, String[] nestedKeyArray, Map currentQueryMap, String value) { + // Return when all levels have been reached. + if(index == nestedKeyArray.length) + return; + + // For the final level simply put the value in the map. + else if (index == nestedKeyArray.length - 1) { + currentQueryMap.put(nestedKeyArray[index], value); + return; + } + + // For non terminal levels, add a child map. + currentQueryMap.put(nestedKeyArray[index], new HashMap<>()); + + // Make a recursive call to enrich data in next level. + prepareNestedQueryMap(index + 1, nestedKeyArray, (Map) currentQueryMap.get(nestedKeyArray[index]), value); + } + +} diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java index d9742177dad..387185f73b0 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java @@ -33,7 +33,7 @@ public ResponseEntity createPost(@Valid @RequestBody PlanRequest b @RequestMapping(value = "/_search", method = RequestMethod.POST) public ResponseEntity searchPost(@Valid @RequestBody PlanSearchRequest body) { PlanResponse planResponse = planService.searchPlan(body); - return ResponseEntity.status(HttpStatus.OK).body(new PlanResponse()); + return ResponseEntity.status(HttpStatus.OK).body(planResponse); } @RequestMapping(value = "/_update", method = RequestMethod.POST) diff --git a/health-services/plan-service/src/main/java/digit/web/models/Activity.java b/health-services/plan-service/src/main/java/digit/web/models/Activity.java index 61fea542a3f..15f15209259 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Activity.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Activity.java @@ -4,6 +4,7 @@ import java.util.List; import jakarta.validation.constraints.Size; +import org.egov.common.contract.models.AuditDetails; import org.springframework.validation.annotation.Validated; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java index f7a32f74f83..6e9cc9449d1 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java @@ -37,4 +37,10 @@ public class PlanSearchCriteria { @JsonProperty("planConfigurationId") private String planConfigurationId = null; + @JsonProperty("offset") + private Integer offset = null; + + @JsonProperty("limit") + private Integer limit = null; + } diff --git a/health-services/plan-service/src/main/resources/application.properties b/health-services/plan-service/src/main/resources/application.properties index fc7fdc13367..ca7f10f4982 100644 --- a/health-services/plan-service/src/main/resources/application.properties +++ b/health-services/plan-service/src/main/resources/application.properties @@ -7,19 +7,19 @@ app.timezone=UTC #DATABASE CONFIGURATION spring.datasource.driver-class-name=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://localhost:5432/plandb +spring.datasource.url=jdbc:postgresql://localhost:5433/plandb spring.datasource.username=postgres spring.datasource.password=postgres #FLYWAY CONFIGURATION -spring.flyway.url=jdbc:postgresql://localhost:5432/plandb +spring.flyway.url=jdbc:postgresql://localhost:5433/plandb spring.flyway.user=postgres spring.flyway.password=postgres spring.flyway.table=public spring.flyway.baseline-on-migrate=true spring.flyway.outOfOrder=true spring.flyway.locations=classpath:/db/migration/main -spring.flyway.enabled=true +spring.flyway.enabled=false # KAFKA SERVER CONFIGURATIONS kafka.config.bootstrap_server_config=localhost:9092 @@ -67,4 +67,8 @@ egov.idgen.host=http://localhost:8081/ egov.idgen.path=egov-idgen/id/_generate # The value of the following field should be changed to service specific name -kafka.topics.consumer=service-consumer-topic \ No newline at end of file +kafka.topics.consumer=service-consumer-topic + +# Pagination config +plan.default.offset=0 +plan.default.limit=10 \ No newline at end of file From b433c44ad56d8f890b98960d4b2d0b1103d07b82 Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Mon, 11 Mar 2024 20:58:35 +0530 Subject: [PATCH 24/53] [HLM-5187] Modified row mapper implementation --- .../repository/impl/PlanRepositoryImpl.java | 3 +- .../repository/rowmapper/PlanRowMapper.java | 63 +++++++++++++++---- .../digit/web/models/PlanEditRequest.java | 2 +- 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java index aaf327a2bbf..25b02f64a86 100644 --- a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java @@ -42,9 +42,10 @@ public void create(PlanRequest planRequest) { @Override public List search(PlanSearchCriteria planSearchCriteria) { + // Fetch plan ids from database List planIds = queryDatabaseForPlanIds(planSearchCriteria); - log.info("Plan ids: " + planIds); + // Fetch plans from database based on the acquired ids List plans = searchPlanByIds(planIds); return plans; diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java index 64cbc2a59a7..cf20654fae3 100644 --- a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java @@ -11,7 +11,6 @@ import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; -import org.springframework.util.StringUtils; import java.io.IOException; import java.sql.ResultSet; @@ -30,6 +29,10 @@ public PlanRowMapper(ObjectMapper objectMapper) { @Override public List extractData(ResultSet rs) throws SQLException, DataAccessException { Map planMap = new LinkedHashMap<>(); + Map activityMap = new LinkedHashMap<>(); + Map conditionMap = new LinkedHashMap<>(); + Map resourceMap = new LinkedHashMap<>(); + Map targetMap = new LinkedHashMap<>(); // Traverse through result set and create plan objects while(rs.next()) { @@ -59,16 +62,25 @@ public List extractData(ResultSet rs) throws SQLException, DataAccessExcep } - addActivities(rs, planEntry); - addResources(rs, planEntry); - addTargets(rs, planEntry); + addActivities(rs, planEntry, activityMap, conditionMap); + addResources(rs, planEntry, resourceMap); + addTargets(rs, planEntry, targetMap); planMap.put(planId, planEntry); } return new ArrayList<>(planMap.values()); } - private void addActivities(ResultSet rs, Plan plan) throws SQLException, DataAccessException { + private void addActivities(ResultSet rs, Plan plan, + Map activityMap, Map conditionMap) throws SQLException, DataAccessException { + + String activityId = rs.getString("plan_activity_id"); + + if(!ObjectUtils.isEmpty(activityId) && activityMap.containsKey(activityId)) { + addActivityConditions(rs, activityMap.get(activityId), conditionMap); + return; + } + String dependencies = rs.getString("plan_activity_dependencies"); AuditDetails auditDetails = AuditDetails.builder() .createdBy(rs.getString("plan_activity_created_by")) @@ -78,7 +90,7 @@ private void addActivities(ResultSet rs, Plan plan) throws SQLException, DataAcc .build(); Activity activity = Activity.builder() - .id(rs.getString("plan_activity_id")) + .id(activityId) .code(rs.getString("plan_activity_code")) .description(rs.getString("plan_activity_description")) .plannedStartDate(rs.getLong("plan_activity_planned_start_date")) @@ -86,7 +98,7 @@ private void addActivities(ResultSet rs, Plan plan) throws SQLException, DataAcc .dependencies(ObjectUtils.isEmpty(dependencies) ? new ArrayList<>() : Arrays.asList(rs.getString("plan_activity_dependencies").split(","))) .build(); - addActivityConditions(rs, activity); + addActivityConditions(rs, activity, conditionMap); if (CollectionUtils.isEmpty(plan.getActivities())) { List activityList = new ArrayList<>(); @@ -96,9 +108,17 @@ private void addActivities(ResultSet rs, Plan plan) throws SQLException, DataAcc plan.getActivities().add(activity); } + activityMap.put(activity.getId(), activity); + } - private void addActivityConditions(ResultSet rs, Activity activity) throws SQLException, DataAccessException { + private void addActivityConditions(ResultSet rs, Activity activity, Map conditionMap) throws SQLException, DataAccessException { + String conditionId = rs.getString("plan_activity_condition_id"); + + if(ObjectUtils.isEmpty(conditionId) || conditionMap.containsKey(conditionId)) { + return; + } + AuditDetails auditDetails = AuditDetails.builder() .createdBy(rs.getString("plan_activity_condition_created_by")) .createdTime(rs.getLong("plan_activity_condition_created_time")) @@ -107,7 +127,7 @@ private void addActivityConditions(ResultSet rs, Activity activity) throws SQLEx .build(); Condition condition = Condition.builder() - .id(rs.getString("plan_activity_condition_id")) + .id(conditionId) .entity(rs.getString("plan_activity_condition_entity")) .entityProperty(rs.getString("plan_activity_condition_entity_property")) .expression(rs.getString("plan_activity_condition_expression")) @@ -121,9 +141,18 @@ private void addActivityConditions(ResultSet rs, Activity activity) throws SQLEx activity.getConditions().add(condition); } + conditionMap.put(condition.getId(), condition); + } - private void addResources(ResultSet rs, Plan planEntry) throws SQLException, DataAccessException { + private void addResources(ResultSet rs, Plan planEntry, Map resourceMap) throws SQLException, DataAccessException { + + String resourceId = rs.getString("plan_resource_id"); + + if(ObjectUtils.isEmpty(resourceId) || resourceMap.containsKey(resourceId)) { + return; + } + AuditDetails auditDetails = AuditDetails.builder() .createdBy(rs.getString("plan_resource_created_by")) .createdTime(rs.getLong("plan_resource_created_time")) @@ -146,9 +175,17 @@ private void addResources(ResultSet rs, Plan planEntry) throws SQLException, Dat planEntry.getResources().add(resource); } + resourceMap.put(resource.getId(), resource); + } - private void addTargets(ResultSet rs, Plan planEntry) throws SQLException, DataAccessException { + private void addTargets(ResultSet rs, Plan planEntry, Map targetMap) throws SQLException, DataAccessException { + String targetId = rs.getString("plan_target_id"); + + if(ObjectUtils.isEmpty(targetId) || targetMap.containsKey(targetId)) { + return; + } + AuditDetails auditDetails = AuditDetails.builder() .createdBy(rs.getString("plan_target_created_by")) .createdTime(rs.getLong("plan_target_created_time")) @@ -163,7 +200,7 @@ private void addTargets(ResultSet rs, Plan planEntry) throws SQLException, DataA .build(); Target target = Target.builder() - .id(rs.getString("plan_target_id")) + .id(targetId) .metric(rs.getString("plan_target_metric")) .metricDetail(metricDetail) .activityCode(rs.getString("plan_target_activity_code")) @@ -177,6 +214,8 @@ private void addTargets(ResultSet rs, Plan planEntry) throws SQLException, DataA planEntry.getTargets().add(target); } + targetMap.put(target.getId(), target); + } private JsonNode getAdditionalDetail(PGobject pGobject){ diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java index 6a41cebcd48..045fe511fdd 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java @@ -18,6 +18,7 @@ @NoArgsConstructor @Builder public class PlanEditRequest { + @JsonProperty("RequestInfo") @Valid private RequestInfo requestInfo = null; @@ -26,5 +27,4 @@ public class PlanEditRequest { @Valid private Plan plan = null; - } From e1d99259d8cc5031ade262dcda4c53ed49ebe564 Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Tue, 12 Mar 2024 14:05:24 +0530 Subject: [PATCH 25/53] [HLM-5134] Implemented update API for plan service --- .../repository/impl/PlanRepositoryImpl.java | 29 +++++ .../main/java/digit/service/PlanEnricher.java | 58 +++++++++- .../main/java/digit/service/PlanService.java | 32 ++++++ .../java/digit/service/PlanValidator.java | 105 +++++++++++++++++- .../digit/web/controllers/PlanController.java | 20 +++- .../digit/web/models/PlanEditRequest.java | 30 ----- 6 files changed, 238 insertions(+), 36 deletions(-) delete mode 100644 health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java index 25b02f64a86..2caeaf45d29 100644 --- a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java @@ -11,6 +11,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.SingleColumnRowMapper; import org.springframework.stereotype.Repository; +import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.List; @@ -35,27 +36,50 @@ public PlanRepositoryImpl(Producer producer, PlanQueryBuilder planQueryBuilder, this.jdbcTemplate = jdbcTemplate; } + /** + * This method emits an event to the persister for it to save the plan in the database. + * @param planRequest + */ @Override public void create(PlanRequest planRequest) { producer.push("save-plan", planRequest); } + /** + * This method searches for plans based on the search criteria. + * @param planSearchCriteria + * @return + */ @Override public List search(PlanSearchCriteria planSearchCriteria) { // Fetch plan ids from database List planIds = queryDatabaseForPlanIds(planSearchCriteria); + // Return empty list back as response if no plan ids are found + if(CollectionUtils.isEmpty(planIds)) { + return new ArrayList<>(); + } + // Fetch plans from database based on the acquired ids List plans = searchPlanByIds(planIds); return plans; } + /** + * This method emits an event to the persister for it to update the plan in the database. + * @param planRequest + */ @Override public void update(PlanRequest planRequest) { producer.push("update-plan", planRequest); } + /** + * Helper method to query database for plan ids based on the provided search criteria. + * @param planSearchCriteria + * @return + */ private List queryDatabaseForPlanIds(PlanSearchCriteria planSearchCriteria) { List preparedStmtList = new ArrayList<>(); String query = planQueryBuilder.getPlanSearchQuery(planSearchCriteria, preparedStmtList); @@ -63,6 +87,11 @@ private List queryDatabaseForPlanIds(PlanSearchCriteria planSearchCriter return jdbcTemplate.query(query, new SingleColumnRowMapper<>(String.class), preparedStmtList.toArray()); } + /** + * Helper method to search for plans based on the provided plan ids. + * @param planIds + * @return + */ private List searchPlanByIds(List planIds) { List preparedStmtList = new ArrayList<>(); String query = planQueryBuilder.getPlanQuery(planIds, preparedStmtList); diff --git a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java index c24eb800032..b45a1798989 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java @@ -5,14 +5,20 @@ import org.egov.common.utils.UUIDEnrichmentUtil; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; @Component public class PlanEnricher { - + /** + * Enriches the plan create request + * @param body + */ public void enrichPlanCreate(PlanRequest body) { // Generate id for plan UUIDEnrichmentUtil.enrichRandomUuid(body.getPlan(), "id"); @@ -47,4 +53,54 @@ public void enrichPlanCreate(PlanRequest body) { .prepareAuditDetails(body.getPlan().getAuditDetails(), body.getRequestInfo(), Boolean.TRUE)); } + + /** + * Enriches the plan update request + * @param body + */ + public void enrichPlanUpdate(PlanRequest body) { + // Generate uuid for new activities + Set newActivityUuids = new HashSet<>(); + body.getPlan().getActivities().forEach(activity -> { + if(ObjectUtils.isEmpty(activity.getId())) { + UUIDEnrichmentUtil.enrichRandomUuid(activity, "id"); + newActivityUuids.add(activity.getId()); + } + }); + + // Generate uuid for new activity conditions + body.getPlan().getActivities().forEach(activity -> { + if(!CollectionUtils.isEmpty(activity.getConditions()) && newActivityUuids.contains(activity.getId())) { + activity.getConditions().forEach(condition -> { + if(ObjectUtils.isEmpty(condition.getId())) { + UUIDEnrichmentUtil.enrichRandomUuid(condition, "id"); + } + }); + } + }); + + // Set empty value in dependencies list when it is empty or null + body.getPlan().getActivities().forEach(activity -> { + if(CollectionUtils.isEmpty(activity.getDependencies())) { + List emptyStringList = new ArrayList<>(); + emptyStringList.add(""); + activity.setDependencies(emptyStringList); + } + }); + + // Generate uuid for new resources + body.getPlan().getResources().forEach(resource -> { + if(ObjectUtils.isEmpty(resource.getId())) { + UUIDEnrichmentUtil.enrichRandomUuid(resource, "id"); + } + }); + + // Generate uuid for new targets + body.getPlan().getTargets().forEach(target -> { + if(ObjectUtils.isEmpty(target.getId())) { + UUIDEnrichmentUtil.enrichRandomUuid(target, "id"); + } + }); + + } } diff --git a/health-services/plan-service/src/main/java/digit/service/PlanService.java b/health-services/plan-service/src/main/java/digit/service/PlanService.java index 976ef2e05a2..c0c97a30eaf 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanService.java @@ -27,6 +27,11 @@ public PlanService(PlanValidator planValidator, PlanEnricher planEnricher, PlanR this.planRepository = planRepository; } + /** + * This method processes the requests that come for creating plans. + * @param body + * @return + */ public PlanResponse createPlan(PlanRequest body) { // Validate plan create request planValidator.validatePlanCreate(body); @@ -44,6 +49,11 @@ public PlanResponse createPlan(PlanRequest body) { .build(); } + /** + * This method processes the requests that come for searching plans. + * @param body + * @return + */ public PlanResponse searchPlan(PlanSearchRequest body) { // Delegate search request to repository List planList = planRepository.search(body.getPlanSearchCriteria()); @@ -54,4 +64,26 @@ public PlanResponse searchPlan(PlanSearchRequest body) { .plan(planList) .build(); } + + /** + * This method processes the requests that come for updating plans. + * @param body + * @return + */ + public PlanResponse updatePlan(PlanRequest body) { + // Validate plan update request + planValidator.validatePlanUpdate(body); + + // Enrich plan update request + planEnricher.enrichPlanUpdate(body); + + // Delegate update request to repository + planRepository.update(body); + + // Build and return response back to controller + return PlanResponse.builder() + .responseInfo(ResponseInfoUtil.createResponseInfoFromRequestInfo(body.getRequestInfo(), Boolean.TRUE)) + .plan(Collections.singletonList(body.getPlan())) + .build(); + } } diff --git a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java index c293ee739a6..e66389aca31 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java @@ -1,12 +1,15 @@ package digit.service; +import digit.repository.PlanRepository; import digit.web.models.Activity; import digit.web.models.PlanRequest; +import digit.web.models.PlanSearchCriteria; import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -15,6 +18,16 @@ @Component public class PlanValidator { + private PlanRepository planRepository; + + public PlanValidator(PlanRepository planRepository) { + this.planRepository = planRepository; + } + + /** + * This method performs business validations on plan create requests + * @param request + */ public void validatePlanCreate(PlanRequest request) { // Validate execution plan existence @@ -40,6 +53,10 @@ public void validatePlanCreate(PlanRequest request) { } + /** + * This validation method validates if the dependent activities are valid and if they form a cycle + * @param request + */ private void validateActivityDependencies(PlanRequest request) { // Check if dependent activity codes are valid validateDependentActivityCodes(request); @@ -48,6 +65,10 @@ private void validateActivityDependencies(PlanRequest request) { checkForCycleInActivityDependencies(request); } + /** + * This method checks if the activity dependencies form a cycle + * @param request + */ private void checkForCycleInActivityDependencies(PlanRequest request) { Map> activityCodeVsDependenciesMap = request.getPlan().getActivities().stream() .collect(Collectors.toMap(Activity::getCode, @@ -61,12 +82,19 @@ private void checkForCycleInActivityDependencies(PlanRequest request) { }); } + /** + * This method validates if the dependent activity codes are valid + * @param request + */ private void validateDependentActivityCodes(PlanRequest request) { + // Collect all activity codes + Set activityCodes = request.getPlan().getActivities().stream() + .map(Activity::getCode) + .collect(Collectors.toSet()); + + // Check if the dependent activity codes are valid request.getPlan().getActivities().forEach(activity -> { if(!CollectionUtils.isEmpty(activity.getDependencies())) { - Set activityCodes = request.getPlan().getActivities().stream() - .map(Activity::getCode) - .collect(Collectors.toSet()); activity.getDependencies().forEach(dependency -> { if(!activityCodes.contains(dependency)) throw new CustomException("INVALID_ACTIVITY_DEPENDENCY", "Activity dependency is invalid"); @@ -75,15 +103,24 @@ private void validateDependentActivityCodes(PlanRequest request) { }); } + /** + * This method validates if the execution plan id provided in the request exists + * @param request + */ private void validateExecutionPlanExistence(PlanRequest request) { } + /** + * This method validates the activities provided in the request + * @param request + */ private void validateActivities(PlanRequest request) { // Validate code uniqueness within activities Set activityCodes = request.getPlan().getActivities().stream() .map(Activity::getCode) .collect(Collectors.toSet()); + // If activity codes are not unique, throw an exception if(activityCodes.size() != request.getPlan().getActivities().size()) { throw new CustomException("DUPLICATE_ACTIVITY_CODES", "Activity codes within the plan should be unique"); } @@ -109,10 +146,18 @@ private void validateActivities(PlanRequest request) { } } + /** + * This method validates if the plan configuration id provided in the request exists + * @param request + */ private void validatePlanConfigurationExistence(PlanRequest request) { } + /** + * This method validates the resources provided in the request + * @param request + */ private void validateResources(PlanRequest request) { // If plan configuration id is not provided, providing resources is mandatory if(ObjectUtils.isEmpty(request.getPlan().getPlanConfigurationId()) @@ -134,12 +179,19 @@ private void validateResources(PlanRequest request) { } } + /** + * This method validates the linkage between resources and activities + * @param request + */ private void validateResourceActivityLinkage(PlanRequest request) { if(ObjectUtils.isEmpty(request.getPlan().getPlanConfigurationId()) && !CollectionUtils.isEmpty(request.getPlan().getActivities())) { + // Collect all activity codes Set activityCodes = request.getPlan().getActivities().stream() .map(Activity::getCode) .collect(Collectors.toSet()); + + // Validate resource-activity linkage request.getPlan().getResources().forEach(resource -> { if(!activityCodes.contains(resource.getActivityCode())) throw new CustomException("INVALID_RESOURCE_ACTIVITY_LINKAGE", "Resource-Activity linkage is invalid"); @@ -147,11 +199,18 @@ private void validateResourceActivityLinkage(PlanRequest request) { } } + /** + * This method validates the linkage between targets and activities + * @param request + */ private void validateTargetActivityLinkage(PlanRequest request) { if(!CollectionUtils.isEmpty(request.getPlan().getActivities())) { + // Collect all activity codes Set activityCodes = request.getPlan().getActivities().stream() .map(Activity::getCode) .collect(Collectors.toSet()); + + // Validate target-activity linkage request.getPlan().getTargets().forEach(target -> { if(!activityCodes.contains(target.getActivityCode())) throw new CustomException("INVALID_TARGET_ACTIVITY_LINKAGE", "Target-Activity linkage is invalid"); @@ -159,4 +218,44 @@ private void validateTargetActivityLinkage(PlanRequest request) { } } + /** + * This method performs business validations on plan update requests + * @param request + */ + public void validatePlanUpdate(PlanRequest request) { + // Validate plan existence + validatePlanExistence(request); + + // Validate activities + validateActivities(request); + + // Validate plan configuration existence + validatePlanConfigurationExistence(request); + + // Validate resources + validateResources(request); + + // Validate resource-activity linkage + validateResourceActivityLinkage(request); + + // Validate target-activity linkage + validateTargetActivityLinkage(request); + + // Validate dependencies + validateActivityDependencies(request); + + } + + /** + * This method validates if the plan id provided in the update request exists + * @param request + */ + private void validatePlanExistence(PlanRequest request) { + // If plan id provided is invalid, throw an exception + if(CollectionUtils.isEmpty(planRepository.search(PlanSearchCriteria.builder() + .ids(Collections.singleton(request.getPlan().getId())) + .build()))) { + throw new CustomException("INVALID_PLAN_ID", "Plan id provided is invalid"); + } + } } diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java index 387185f73b0..2381b009d40 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanController.java @@ -24,21 +24,37 @@ public PlanController(PlanService planService) { this.planService = planService; } + /** + * Request handler for serving plan create requests + * @param body + * @return + */ @RequestMapping(value = "/_create", method = RequestMethod.POST) public ResponseEntity createPost(@Valid @RequestBody PlanRequest body) { PlanResponse planResponse = planService.createPlan(body); return ResponseEntity.status(HttpStatus.ACCEPTED).body(planResponse); } + /** + * Request handler for serving plan search requests + * @param body + * @return + */ @RequestMapping(value = "/_search", method = RequestMethod.POST) public ResponseEntity searchPost(@Valid @RequestBody PlanSearchRequest body) { PlanResponse planResponse = planService.searchPlan(body); return ResponseEntity.status(HttpStatus.OK).body(planResponse); } + /** + * Request handler for serving plan update requests + * @param body + * @return + */ @RequestMapping(value = "/_update", method = RequestMethod.POST) - public ResponseEntity updatePost(@Valid @RequestBody PlanEditRequest body) { - return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanResponse()); + public ResponseEntity updatePost(@Valid @RequestBody PlanRequest body) { + PlanResponse planResponse = planService.updatePlan(body); + return ResponseEntity.status(HttpStatus.ACCEPTED).body(planResponse); } } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java b/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java deleted file mode 100644 index 045fe511fdd..00000000000 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanEditRequest.java +++ /dev/null @@ -1,30 +0,0 @@ -package digit.web.models; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.egov.common.contract.request.RequestInfo; -import org.springframework.validation.annotation.Validated; -import jakarta.validation.Valid; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; -import lombok.Data; -import lombok.Builder; - -/** - * PlanEditRequest - */ -@Validated -@Data -@AllArgsConstructor -@NoArgsConstructor -@Builder -public class PlanEditRequest { - - @JsonProperty("RequestInfo") - @Valid - private RequestInfo requestInfo = null; - - @JsonProperty("Plan") - @Valid - private Plan plan = null; - -} From 0107f2733d805bfd2148b032ab613c6551700c0a Mon Sep 17 00:00:00 2001 From: Shashwat Mishra Date: Tue, 12 Mar 2024 14:42:41 +0530 Subject: [PATCH 26/53] [HLM-5129] Added validations in update API --- .../java/digit/service/PlanValidator.java | 51 +++++++++++++++++-- .../src/main/java/digit/web/models/Plan.java | 4 +- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java index e66389aca31..a307f914025 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java @@ -1,9 +1,7 @@ package digit.service; import digit.repository.PlanRepository; -import digit.web.models.Activity; -import digit.web.models.PlanRequest; -import digit.web.models.PlanSearchCriteria; +import digit.web.models.*; import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -115,7 +113,7 @@ private void validateExecutionPlanExistence(PlanRequest request) { * @param request */ private void validateActivities(PlanRequest request) { - // Validate code uniqueness within activities + // Collect all activity codes Set activityCodes = request.getPlan().getActivities().stream() .map(Activity::getCode) .collect(Collectors.toSet()); @@ -229,12 +227,21 @@ public void validatePlanUpdate(PlanRequest request) { // Validate activities validateActivities(request); + // Validate activities uuid uniqueness + validateActivitiesUuidUniqueness(request); + // Validate plan configuration existence validatePlanConfigurationExistence(request); // Validate resources validateResources(request); + // Validate resource uuid uniqueness + validateResourceUuidUniqueness(request); + + // Validate target uuid uniqueness + validateTargetUuidUniqueness(request); + // Validate resource-activity linkage validateResourceActivityLinkage(request); @@ -246,6 +253,42 @@ public void validatePlanUpdate(PlanRequest request) { } + private void validateTargetUuidUniqueness(PlanRequest request) { + // Collect all target uuids + Set targetUuids = request.getPlan().getTargets().stream() + .map(Target::getId) + .collect(Collectors.toSet()); + + // If target uuids are not unique, throw an exception + if(targetUuids.size() != request.getPlan().getTargets().size()) { + throw new CustomException("DUPLICATE_TARGET_UUIDS", "Target uuids should be unique"); + } + } + + private void validateResourceUuidUniqueness(PlanRequest request) { + // Collect all resource uuids + Set resourceUuids = request.getPlan().getResources().stream() + .map(Resource::getId) + .collect(Collectors.toSet()); + + // If resource uuids are not unique, throw an exception + if(resourceUuids.size() != request.getPlan().getResources().size()) { + throw new CustomException("DUPLICATE_RESOURCE_UUIDS", "Resource uuids should be unique"); + } + } + + private void validateActivitiesUuidUniqueness(PlanRequest request) { + // Collect all activity uuids + Set activityUuids = request.getPlan().getActivities().stream() + .map(Activity::getId) + .collect(Collectors.toSet()); + + // If activity uuids are not unique, throw an exception + if(activityUuids.size() != request.getPlan().getActivities().size()) { + throw new CustomException("DUPLICATE_ACTIVITY_UUIDS", "Activity uuids should be unique"); + } + } + /** * This method validates if the plan id provided in the update request exists * @param request diff --git a/health-services/plan-service/src/main/java/digit/web/models/Plan.java b/health-services/plan-service/src/main/java/digit/web/models/Plan.java index 41e06bfcdb6..6001d223ef6 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Plan.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Plan.java @@ -36,11 +36,11 @@ public class Plan { private String locality = null; @JsonProperty("executionPlanId") - @Size(min = 64, max = 64) + @Size(max = 64) private String executionPlanId = null; @JsonProperty("planConfigurationId") - @Size(min = 64, max = 64) + @Size(max = 64) private String planConfigurationId = null; @JsonProperty("additionalDetails") From 136b212899d6d6d9083cd0a6cb272018f86573ed Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 12 Mar 2024 14:46:20 +0530 Subject: [PATCH 27/53] HLM-5116 changes for search API --- .../main/java/digit/config/Configuration.java | 5 + .../PlanConfigurationRepository.java | 5 +- .../impl/PlanConfigurationRepositoryImpl.java | 25 ++- .../querybuilder/PlanConfigQueryBuilder.java | 115 +++++++++++ .../rowmapper/PlanConfigRowMapper.java | 190 ++++++++++++++++++ .../service/PlanConfigurationService.java | 9 +- .../validator/PlanConfigurationValidator.java | 16 ++ .../web/controllers/PlanConfigController.java | 25 ++- .../PlanConfigurationSearchCriteria.java | 14 +- 9 files changed, 387 insertions(+), 17 deletions(-) create mode 100644 health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java create mode 100644 health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java diff --git a/health-services/plan-service/src/main/java/digit/config/Configuration.java b/health-services/plan-service/src/main/java/digit/config/Configuration.java index cced66a6137..90f5e57de25 100644 --- a/health-services/plan-service/src/main/java/digit/config/Configuration.java +++ b/health-services/plan-service/src/main/java/digit/config/Configuration.java @@ -21,6 +21,7 @@ @Getter public class Configuration { + //Workflow Config @Value("${egov.workflow.host}") private String wfHost; @@ -33,12 +34,16 @@ public class Configuration { @Value("${egov.workflow.processinstance.search.path}") private String wfProcessInstanceSearchPath; + + //MDMS @Value("${egov.mdms.host}") private String mdmsHost; @Value("${egov.mdms.search.endpoint}") private String mdmsEndPoint; + + //Persister Topic @Value("${plan.configuration.create.topic}") private String planConfigCreateTopic; diff --git a/health-services/plan-service/src/main/java/digit/repository/PlanConfigurationRepository.java b/health-services/plan-service/src/main/java/digit/repository/PlanConfigurationRepository.java index d0e303e4650..49efc1d89f4 100644 --- a/health-services/plan-service/src/main/java/digit/repository/PlanConfigurationRepository.java +++ b/health-services/plan-service/src/main/java/digit/repository/PlanConfigurationRepository.java @@ -1,7 +1,10 @@ package digit.repository; +import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; +import digit.web.models.PlanConfigurationSearchCriteria; +import java.util.List; import org.springframework.stereotype.Repository; @@ -9,7 +12,7 @@ public interface PlanConfigurationRepository { public void create(PlanConfigurationRequest planConfigurationRequest); - public void search(PlanConfigurationRequest planConfigurationRequest); + public List search(PlanConfigurationSearchCriteria planConfigurationSearchCriteria); public void update(PlanConfigurationRequest planConfigurationRequest); diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java index b086b764e74..8e18b15bf41 100644 --- a/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java @@ -3,9 +3,14 @@ import digit.config.Configuration; import digit.kafka.Producer; import digit.repository.PlanConfigurationRepository; +import digit.repository.querybuilder.PlanConfigQueryBuilder; +import digit.repository.rowmapper.PlanConfigRowMapper; +import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; +import digit.web.models.PlanConfigurationSearchCriteria; +import java.util.ArrayList; +import java.util.List; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -14,14 +19,22 @@ public class PlanConfigurationRepositoryImpl implements PlanConfigurationRepository { private Producer producer; + private JdbcTemplate jdbcTemplate; + private Configuration config; + private PlanConfigQueryBuilder planConfigQueryBuilder; + + private PlanConfigRowMapper planConfigRowMapper; + public PlanConfigurationRepositoryImpl(Producer producer, JdbcTemplate jdbcTemplate, - Configuration config) { + Configuration config, PlanConfigQueryBuilder planConfigQueryBuilder, PlanConfigRowMapper planConfigRowMapper) { this.producer = producer; this.jdbcTemplate = jdbcTemplate; this.config = config; + this.planConfigQueryBuilder = planConfigQueryBuilder; + this.planConfigRowMapper = planConfigRowMapper; } @Override @@ -30,8 +43,12 @@ public void create(PlanConfigurationRequest planConfigurationRequest) { } @Override - public void search(PlanConfigurationRequest planConfigurationRequest) { - log.info("Search Method"); + public List search(PlanConfigurationSearchCriteria planConfigurationSearchCriteria) { + List preparedStmtList = new ArrayList<>(); + String query = planConfigQueryBuilder.getPlanConfigSearchQuery(planConfigurationSearchCriteria, preparedStmtList); + log.info("Plan Config query: " + query); + log.info("preparedStmtList: " + preparedStmtList); + return jdbcTemplate.query(query, preparedStmtList.toArray(), planConfigRowMapper); } @Override diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java new file mode 100644 index 00000000000..b44dc7fe862 --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java @@ -0,0 +1,115 @@ +package digit.repository.querybuilder; + +import digit.config.Configuration; + +import digit.util.QueryUtil; +import digit.web.models.PlanConfigurationSearchCriteria; +import java.util.List; +import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; + +@Component +public class PlanConfigQueryBuilder { + + private Configuration config; + + public PlanConfigQueryBuilder(Configuration config) { + this.config = config; + } + + private static final String PLAN_CONFIG_BASE_SEARCH_QUERY = "SELECT pc.id as plan_configuration_id, pc.tenant_id as plan_configuration_tenant_id, pc.name as plan_configuration_name, pc.execution_plan_id as plan_configuration_execution_plan_id, pc.created_by as plan_configuration_created_by, pc.created_time as plan_configuration_created_time, pc.last_modified_by as plan_configuration_last_modified_by, pc.last_modified_time as plan_configuration_last_modified_time, \n" + + "\t pcf.id as plan_configuration_files_id, pcf.plan_configuration_id as plan_configuration_files_plan_configuration_id, pcf.filestore_id as plan_configuration_files_filestore_id, pcf.input_file_type as plan_configuration_files_input_file_type, pcf.created_by as plan_configuration_files_created_by, pcf.created_time as plan_configuration_files_created_time, pcf.last_modified_by as plan_configuration_files_last_modified_by, pcf.last_modified_time as plan_configuration_files_last_modified_time,\n" + + "\t pca.id as plan_configuration_assumptions_id, pca.key as plan_configuration_assumptions_key, pca.value as plan_configuration_assumptions_value, pca.plan_configuration_id as plan_configuration_assumptions_plan_configuration_id, pca.created_by as plan_configuration_assumptions_created_by, pca.created_time as plan_configuration_assumptions_created_time, pca.last_modified_by as plan_configuration_assumptions_last_modified_by, pca.last_modified_time as plan_configuration_assumptions_last_modified_time,\n" + + "\t pco.id as plan_configuration_operations_id, pco.input as plan_configuration_operations_input, pco.operator as plan_configuration_operations_operator, pco.assumption_value as plan_configuration_operations_assumption_value, pco.output as plan_configuration_operations_output, pco.plan_configuration_id as plan_configuration_operations_plan_configuration_id, pco.created_by as plan_configuration_operations_created_by, pco.created_time as plan_configuration_operations_created_time, pco.last_modified_by as plan_configuration_operations_last_modified_by, pco.last_modified_time as plan_configuration_operations_last_modified_time,\n" + + "\t pcm.id as plan_configuration_mapping_id, pcm.mapped_from as plan_configuration_mapping_mapped_from, pcm.mapped_to as plan_configuration_mapping_mapped_to, pcm.plan_configuration_id as plan_configuration_mapping_plan_configuration_id, pcm.created_by as plan_configuration_mapping_created_by, pcm.created_time as plan_configuration_mapping_created_time, pcm.last_modified_by as plan_configuration_mapping_last_modified_by, pcm.last_modified_time as plan_configuration_mapping_last_modified_time\n" + + "\t FROM plan_configuration pc\n" + + "\t LEFT JOIN plan_configuration_files pcf ON pc.id = pcf.plan_configuration_id\n" + + "\t LEFT JOIN plan_configuration_assumptions pca ON pc.id = pca.plan_configuration_id\n" + + "\t LEFT JOIN plan_configuration_operations pco ON pc.id = pco.plan_configuration_id\n" + + "\t LEFT JOIN plan_configuration_mapping pcm ON pc.id = pcm.plan_configuration_id"; + + private static final String PLAN_CONFIG_SEARCH_QUERY_ORDER_BY_CLAUSE = " ORDER BY pc.last_modified_time DESC "; + + /** + * Constructs a SQL query string for searching PlanConfiguration objects based on the provided search criteria. + * Also adds an ORDER BY clause and handles pagination. + * + * @param criteria The criteria used for filtering PlanConfiguration objects. + * @param preparedStmtList A list to store prepared statement parameters. + * @return A complete SQL query string for searching PlanConfiguration objects. + */ + public String getPlanConfigSearchQuery(PlanConfigurationSearchCriteria criteria, List preparedStmtList) { + String query = buildPlanConfigSearchQuery(criteria, preparedStmtList); + query = QueryUtil.addOrderByClause(query, PLAN_CONFIG_SEARCH_QUERY_ORDER_BY_CLAUSE); + query = getPaginatedQuery(query, criteria, preparedStmtList); + + return query; + } + + /** + * Constructs query based on the provided search criteria + * + * @param criteria The criteria used for filtering PlanConfiguration objects. + * @param preparedStmtList A list to store prepared statement parameters. + * @return + */ + private String buildPlanConfigSearchQuery(PlanConfigurationSearchCriteria criteria, List preparedStmtList) { + StringBuilder builder = new StringBuilder(PLAN_CONFIG_BASE_SEARCH_QUERY); + + if (criteria.getTenantId() != null) { + addClauseIfRequired(preparedStmtList, builder); + builder.append(" pc.tenant_id = ?"); + preparedStmtList.add(criteria.getTenantId()); + } + + if (criteria.getId() != null) { + addClauseIfRequired(preparedStmtList, builder); + builder.append(" pc.id = ?"); + preparedStmtList.add(criteria.getId()); + } + + if (criteria.getExecutionPlanId() != null) { + addClauseIfRequired(preparedStmtList, builder); + builder.append(" pc.execution_plan_id = ?"); + preparedStmtList.add(criteria.getExecutionPlanId()); + } + + if (criteria.getName() != null) { + addClauseIfRequired(preparedStmtList, builder); + builder.append(" pc.name = ?"); + preparedStmtList.add(criteria.getName()); + } + + return builder.toString(); + } + + private void addClauseIfRequired(List preparedStmtList, StringBuilder queryString) { + if (preparedStmtList.isEmpty()) { + queryString.append(" WHERE "); + } else { + queryString.append(" AND"); + } + } + + /** + * @param query prepared Query + * @param planConfigurationSearchCriteria plan config search criteria + * @param preparedStmtList values to be replaced on the query + * @return the query by replacing the placeholders with preparedStmtList + */ + private String getPaginatedQuery(String query, PlanConfigurationSearchCriteria planConfigurationSearchCriteria, List preparedStmtList) { + StringBuilder paginatedQuery = new StringBuilder(query); + + // Append offset + paginatedQuery.append(" OFFSET ? "); + preparedStmtList.add(ObjectUtils.isEmpty(planConfigurationSearchCriteria.getOffset()) ? config.getDefaultOffset() : planConfigurationSearchCriteria.getOffset()); + + // Append limit + paginatedQuery.append(" LIMIT ? "); + preparedStmtList.add(ObjectUtils.isEmpty(planConfigurationSearchCriteria.getLimit()) ? config.getDefaultLimit() : planConfigurationSearchCriteria.getLimit()); + + return paginatedQuery.toString(); + } + +} + diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java new file mode 100644 index 00000000000..7ca8ea2d8b3 --- /dev/null +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java @@ -0,0 +1,190 @@ +package digit.repository.rowmapper; + +import digit.web.models.Assumption; +import digit.web.models.File; +import digit.web.models.Operation; +import digit.web.models.PlanConfiguration; +import digit.web.models.ResourceMapping; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.egov.common.contract.models.AuditDetails; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; + +@Component +public class PlanConfigRowMapper implements ResultSetExtractor> { + + @Override + public List extractData(ResultSet rs) throws SQLException, DataAccessException { + Map planConfigurationMap = new LinkedHashMap<>(); + Map fileMap = new LinkedHashMap<>(); + Map operationMap = new LinkedHashMap<>(); + Map assumptionMap = new LinkedHashMap<>(); + Map resourceMappingMap = new LinkedHashMap<>(); + + + while (rs.next()) { + String planConfigId = rs.getString("plan_configuration_id"); + + PlanConfiguration planConfigEntry = planConfigurationMap.get(planConfigId); + + if (ObjectUtils.isEmpty(planConfigEntry)) { + planConfigEntry = new PlanConfiguration(); + + // Prepare audit details + AuditDetails auditDetails = AuditDetails.builder().createdBy(rs.getString("plan_configuration_created_by")).createdTime(rs.getLong("plan_configuration_created_time")).lastModifiedBy(rs.getString("plan_configuration_last_modified_by")).lastModifiedTime(rs.getLong("plan_configuration_last_modified_time")).build(); + + // Prepare plan object + planConfigEntry.setId(planConfigId); + planConfigEntry.setTenantId(rs.getString("plan_configuration_tenant_id")); + planConfigEntry.setName(rs.getString("plan_configuration_name")); + planConfigEntry.setExecutionPlanId(rs.getString("plan_configuration_execution_plan_id")); + planConfigEntry.setAuditDetails(auditDetails); + + } + addFiles(rs, planConfigEntry, fileMap); + addAssumptions(rs, planConfigEntry, assumptionMap); + addOperations(rs, planConfigEntry, operationMap); + addResourceMappings(rs, planConfigEntry, resourceMappingMap); + + planConfigurationMap.put(planConfigId, planConfigEntry); + } + return new ArrayList<>(planConfigurationMap.values()); + } + + /** + * Adds a File object to the PlanConfiguration entry based on the result set. + * + * @param rs The ResultSet containing the data. + * @param planConfigEntry The PlanConfiguration entry to which the File object will be added. + * @param fileMap A map to keep track of added File objects. + * @throws SQLException If an SQL error occurs. + */ + private void addFiles(ResultSet rs, PlanConfiguration planConfigEntry, Map fileMap) throws SQLException { + String fileId = rs.getString("plan_configuration_files_id"); + + if (ObjectUtils.isEmpty(fileId) || fileMap.containsKey(fileId)) { + return; + } + + File file = new File(); + file.setId(fileId); + file.setFilestoreId(rs.getString("plan_configuration_files_filestore_id")); + System.out.println(rs.getString("plan_configuration_files_input_file_type")); + file.setInputFileType(File.InputFileTypeEnum.valueOf(rs.getString("plan_configuration_files_input_file_type").toUpperCase())); + + if (CollectionUtils.isEmpty(planConfigEntry.getFiles())) { + List fileList = new ArrayList<>(); + fileList.add(file); + planConfigEntry.setFiles(fileList); + } else { + planConfigEntry.getFiles().add(file); + } + + fileMap.put(fileId, file); + } + + + /** + * Adds an Assumption object to the PlanConfiguration entry based on the result set. + * + * @param rs The ResultSet containing the data. + * @param planConfigEntry The PlanConfiguration entry to which the Assumption object will be added. + * @param assumptionMap A map to keep track of added Assumption objects. + * @throws SQLException If an SQL error occurs. + */ + private void addAssumptions(ResultSet rs, PlanConfiguration planConfigEntry, Map assumptionMap) throws SQLException { + String assumptionId = rs.getString("plan_configuration_assumptions_id"); + + if (ObjectUtils.isEmpty(assumptionId) || assumptionMap.containsKey(assumptionId)) { + return; + } + + Assumption assumption = new Assumption(); + assumption.setId(assumptionId); + assumption.setKey(rs.getString("plan_configuration_assumptions_key")); + assumption.setValue(rs.getBigDecimal("plan_configuration_assumptions_value")); + + if (CollectionUtils.isEmpty(planConfigEntry.getAssumptions())) { + List assumptionList = new ArrayList<>(); + assumptionList.add(assumption); + planConfigEntry.setAssumptions(assumptionList); + } else { + planConfigEntry.getAssumptions().add(assumption); + } + + assumptionMap.put(assumptionId, assumption); + } + + /** + * Adds an Operation object to the PlanConfiguration entry based on the result set. + * + * @param rs The ResultSet containing the data. + * @param planConfigEntry The PlanConfiguration entry to which the Operation object will be added. + * @param operationMap A map to keep track of added Operation objects. + * @throws SQLException If an SQL error occurs. + */ + private void addOperations(ResultSet rs, PlanConfiguration planConfigEntry, Map operationMap) throws SQLException { + String operationId = rs.getString("plan_configuration_operations_id"); + + if (ObjectUtils.isEmpty(operationId) || operationMap.containsKey(operationId)) { + return; + } + + Operation operation = new Operation(); + operation.setId(operationId); + operation.setInput(rs.getString("plan_configuration_operations_input")); + operation.setOperator(Operation.OperatorEnum.fromValue(rs.getString("plan_configuration_operations_operator"))); + operation.setAssumptionValue(rs.getString("plan_configuration_operations_assumption_value")); + operation.setOutput(rs.getString("plan_configuration_operations_output")); + + if (CollectionUtils.isEmpty(planConfigEntry.getOperations())) { + List operationList = new ArrayList<>(); + operationList.add(operation); + planConfigEntry.setOperations(operationList); + } else { + planConfigEntry.getOperations().add(operation); + } + + operationMap.put(operationId, operation); + } + + /** + * Adds a ResourceMapping object to the PlanConfiguration entry based on the result set. + * + * @param rs The ResultSet containing the data. + * @param planConfigEntry The PlanConfiguration entry to which the ResourceMapping object will be added. + * @param mappingMap A map to keep track of added ResourceMapping objects. + * @throws SQLException If an SQL error occurs. + */ + private void addResourceMappings(ResultSet rs, PlanConfiguration planConfigEntry, Map mappingMap) throws SQLException { + String mappingId = rs.getString("plan_configuration_mapping_id"); + + if (ObjectUtils.isEmpty(mappingId) || mappingMap.containsKey(mappingId)) { + return; + } + + ResourceMapping mapping = new ResourceMapping(); + mapping.setId(mappingId); + mapping.setMappedFrom(rs.getString("plan_configuration_mapping_mapped_from")); + mapping.setMappedTo(rs.getString("plan_configuration_mapping_mapped_to")); + + if (CollectionUtils.isEmpty(planConfigEntry.getResourceMapping())) { + List mappingList = new ArrayList<>(); + mappingList.add(mapping); + planConfigEntry.setResourceMapping(mappingList); + } else { + planConfigEntry.getResourceMapping().add(mapping); + } + + mappingMap.put(mappingId, mapping); + } + +} diff --git a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java index c59e5bc4bf7..7b782e3279b 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java @@ -2,12 +2,14 @@ import digit.config.Configuration; import digit.kafka.Producer; -import digit.repository.PlanConfigurationRepository; import digit.repository.impl.PlanConfigurationRepositoryImpl; import digit.service.enrichment.EnrichmentService; import digit.service.validator.PlanConfigurationValidator; +import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; +import digit.web.models.PlanConfigurationSearchRequest; +import java.util.List; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -40,4 +42,9 @@ public PlanConfigurationRequest create(PlanConfigurationRequest request) { repository.create(request); return request; } + + public List search(PlanConfigurationSearchRequest request) { + validator.validateSearchRequest(request); + return repository.search(request.getPlanConfigurationSearchCriteria()); + } } \ No newline at end of file diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index 1dc0211e893..512a8e611f2 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -6,11 +6,14 @@ import digit.web.models.Operation; import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; +import digit.web.models.PlanConfigurationSearchRequest; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.egov.tracer.model.CustomException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -73,4 +76,17 @@ public void validateAssumptionKeyAgainstMDMS(PlanConfigurationRequest request) { } } + public void validateSearchRequest(PlanConfigurationSearchRequest planConfigurationSearchRequest) { + validateSearchCriteria(planConfigurationSearchRequest); + } + + private void validateSearchCriteria(PlanConfigurationSearchRequest planConfigurationSearchRequest) { + if (Objects.isNull(planConfigurationSearchRequest.getPlanConfigurationSearchCriteria())) { + throw new CustomException("SEARCH CRITERIA CANNOT BE EMPTY", "Search criteria cannot be empty"); + } + + if (StringUtils.isEmpty(planConfigurationSearchRequest.getPlanConfigurationSearchCriteria().getTenantId())) { + throw new CustomException("TENANT ID CANNOT BE EMPTY", "Tenant Id cannot be empty, TenantId should be present"); + } + } } diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java index 944b1bae745..48b7684b122 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java @@ -2,6 +2,8 @@ import digit.service.PlanConfigurationService; +import digit.util.ResponseInfoFactory; +import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; import digit.web.models.PlanConfigurationResponse; import digit.web.models.PlanConfigurationSearchRequest; @@ -10,7 +12,6 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.media.Schema; -import org.egov.common.contract.response.ResponseInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -27,28 +28,34 @@ public class PlanConfigController { private PlanConfigurationService planConfigurationService; + private ResponseInfoFactory responseInfoFactory; + @Autowired - public PlanConfigController(ObjectMapper objectMapper, PlanConfigurationService planConfigurationService) { + public PlanConfigController(ObjectMapper objectMapper, PlanConfigurationService planConfigurationService, ResponseInfoFactory responseInfoFactory) { this.objectMapper = objectMapper; this.planConfigurationService = planConfigurationService; + this.responseInfoFactory = responseInfoFactory; } @RequestMapping(value = "/config/_create", method = RequestMethod.POST) public ResponseEntity configCreatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationRequest body) { - PlanConfigurationRequest planConfigurationRequest = planConfigurationService.create(body); - PlanConfigurationResponse response = PlanConfigurationResponse.builder() - .planConfiguration(Collections.singletonList(planConfigurationRequest.getPlanConfiguration())) - .responseInfo(new ResponseInfo()) - .build(); + PlanConfigurationRequest planConfigurationRequest = planConfigurationService.create(body); + PlanConfigurationResponse response = PlanConfigurationResponse.builder() + .planConfiguration(Collections.singletonList(planConfigurationRequest.getPlanConfiguration())) + .responseInfo(responseInfoFactory + .createResponseInfoFromRequestInfo(body.getRequestInfo(), true)) + .build(); - return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); + return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); } @RequestMapping(value = "/config/_search", method = RequestMethod.POST) public ResponseEntity configSearchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationSearchRequest body) { - return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanConfigurationResponse()); + List planConfigurationList = planConfigurationService.search(body); + PlanConfigurationResponse response = PlanConfigurationResponse.builder().responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(body.getRequestInfo(), true)).planConfiguration(planConfigurationList).build(); + return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); } @RequestMapping(value = "/config/_update", method = RequestMethod.POST) diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java index f0173e47284..7dbb516e1d3 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java @@ -21,11 +21,21 @@ public class PlanConfigurationSearchCriteria { @Size(min = 1, max = 100) private String tenantId = null; + @JsonProperty("id") + private String id = null; + @JsonProperty("name") private String name = null; - @JsonProperty("executionPlan") - private String executionPlan = null; + @JsonProperty("executionPlanId") + private String executionPlanId = null; + + @JsonProperty("offset") + private Integer offset; + + @JsonProperty("limit") + private Integer limit; + } From 9deb13dd0e0d1e540d70373ddc87eed3b27ef44a Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 13 Mar 2024 11:18:32 +0530 Subject: [PATCH 28/53] HLM-5143 adding different Dockerfile for Java 17 --- build/17/maven/Dockerfile | 34 ++++++++++++++++++++++++++++++++++ build/17/maven/start.sh | 11 +++++++++++ build/build-config.yml | 2 +- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 build/17/maven/Dockerfile create mode 100644 build/17/maven/start.sh diff --git a/build/17/maven/Dockerfile b/build/17/maven/Dockerfile new file mode 100644 index 00000000000..0816437a705 --- /dev/null +++ b/build/17/maven/Dockerfile @@ -0,0 +1,34 @@ + +FROM egovio/amazoncorretto:17-alpine3.19 AS build +# FROM egovio/alpine-maven-builder-jdk-8:1-master-NA-6036091e AS build +#FROM ghcr.io/egovernments/alpine-maven-builder-jdk-8:1-master-na-6036091e AS build +ARG WORK_DIR +WORKDIR /app + +# Install Maven +RUN apk add --no-cache maven + +# copy the project files +COPY ${WORK_DIR}/pom.xml ./pom.xml +COPY build/maven/start.sh ./start.sh + +# not useful for stateless builds +# RUN mvn -B dependency:go-offline + +COPY ${WORK_DIR}/src ./src +RUN mvn -B -f /app/pom.xml package + + +# Create runtime image +#FROM egovio/8-openjdk-alpine +#FROM ghcr.io/egovernments/8-openjdk-alpine:latest +FROM egovio/amazoncorretto:17-alpine3.19 + + +WORKDIR /opt/egov + +COPY --from=build /app/target/*.jar /app/start.sh /opt/egov/ + +RUN chmod +x /opt/egov/start.sh + +CMD ["/opt/egov/start.sh"] diff --git a/build/17/maven/start.sh b/build/17/maven/start.sh new file mode 100644 index 00000000000..08bdd8de28e --- /dev/null +++ b/build/17/maven/start.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +if [[ -z "${JAVA_OPTS}" ]];then + export JAVA_OPTS="-Xmx64m -Xms64m" +fi + +if [ x"${JAVA_ENABLE_DEBUG}" != x ] && [ "${JAVA_ENABLE_DEBUG}" != "false" ]; then + java_debug_args="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${JAVA_DEBUG_PORT:-5005}" +fi + +exec java ${java_debug_args} ${JAVA_OPTS} ${JAVA_ARGS} -jar /opt/egov/*.jar \ No newline at end of file diff --git a/build/build-config.yml b/build/build-config.yml index b54023b9eda..716a2f65ae3 100644 --- a/build/build-config.yml +++ b/build/build-config.yml @@ -172,6 +172,6 @@ config: build: - work-dir: "health-services/plan-service" image-name: "plan-service" - dockerfile: "build/maven/Dockerfile" + dockerfile: "build/17/maven/Dockerfile" - work-dir: "health-services/plan-service/src/main/resources/db" image-name: "plan-service-db" From c57fde70d935f932249a5f61c1d20cad9c5dd957 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 13 Mar 2024 11:44:41 +0530 Subject: [PATCH 29/53] HLM-5143 removing start.sh --- build/17/maven/start.sh | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 build/17/maven/start.sh diff --git a/build/17/maven/start.sh b/build/17/maven/start.sh deleted file mode 100644 index 08bdd8de28e..00000000000 --- a/build/17/maven/start.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -if [[ -z "${JAVA_OPTS}" ]];then - export JAVA_OPTS="-Xmx64m -Xms64m" -fi - -if [ x"${JAVA_ENABLE_DEBUG}" != x ] && [ "${JAVA_ENABLE_DEBUG}" != "false" ]; then - java_debug_args="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${JAVA_DEBUG_PORT:-5005}" -fi - -exec java ${java_debug_args} ${JAVA_OPTS} ${JAVA_ARGS} -jar /opt/egov/*.jar \ No newline at end of file From 5b819ceabd779075ac3f55de845682972716e79e Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 13 Mar 2024 16:25:07 +0530 Subject: [PATCH 30/53] HLM-5116 added tenantId related validations --- .../java/digit/config/ServiceConstants.java | 12 +++- .../rowmapper/PlanConfigRowMapper.java | 1 - .../service/PlanConfigurationService.java | 2 +- .../validator/PlanConfigurationValidator.java | 51 ++++++++++++--- .../src/main/java/digit/util/MdmsUtil.java | 63 ++++++++++++------- .../digit/web/models/PlanConfiguration.java | 5 ++ .../PlanConfigurationSearchCriteria.java | 3 +- 7 files changed, 101 insertions(+), 36 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index aeb4ec21764..1cb0a0169bb 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -55,12 +55,22 @@ public class ServiceConstants { public static final String ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_CODE = "ASSUMPTION_KEY_NOT_FOUND_IN_MDMS"; public static final String ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_MESSAGE = "Assumption Key is not present in MDMS"; - public static final String MDMS_PLAN_ASSUMPTION_MODULE_NAME = "hcm-microplanning"; + public static final String TENANT_NOT_FOUND_IN_MDMS_CODE = "TENANT_ID_NOT_FOUND_IN_MDMS"; + public static final String TENANT_NOT_FOUND_IN_MDMS_MESSAGE = "Tenant Id is not present in MDMS"; + + public static final String NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_CODE = "NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT"; + public static final String NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_MESSAGE = "Invalid or incorrect TenantId. No mdms data found for provided Tenant."; + public static final String MDMS_PLAN_ASSUMPTION_MODULE_NAME = "hcm-microplanning"; public static final String MDMS_MASTER_ASSUMPTION = "Assumptions"; + public static final String MDSM_MASTER_TENANTS = "tenants"; + public static final String MDMS_TENANT_MODULE_NAME = "tenant"; public static final String DOT_SEPARATOR = "."; public static final String DOT_REGEX = "\\."; + public static final String FILTER_CODE = "$.*.code"; + + } diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java index 7ca8ea2d8b3..fcb0f046a04 100644 --- a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java @@ -77,7 +77,6 @@ private void addFiles(ResultSet rs, PlanConfiguration planConfigEntry, Map tenantListFromMDMS = null; + try { + log.info(jsonPathForTenant); + tenantListFromMDMS = JsonPath.read(mdmsData, jsonPathForTenant); + } catch (Exception e) { + log.error(e.getMessage()); + throw new CustomException("JSONPATH_ERROR", "Failed to parse mdms response"); + } + + if (!tenantListFromMDMS.contains(planConfiguration.getTenantId())) { + log.error("The tenant: " + planConfiguration.getTenantId() + " is not present in MDMS"); + throw new CustomException(TENANT_NOT_FOUND_IN_MDMS_CODE, TENANT_NOT_FOUND_IN_MDMS_MESSAGE); + } + } public void validateAssumptionValue(PlanConfiguration planConfiguration) { @@ -51,11 +88,9 @@ public void validateAssumptionValue(PlanConfiguration planConfiguration) { } } - public void validateAssumptionKeyAgainstMDMS(PlanConfigurationRequest request) { + public void validateAssumptionKeyAgainstMDMS(PlanConfigurationRequest request, Object mdmsData) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); - String rootTenantId = planConfiguration.getTenantId().split("\\.")[0]; - Object mdmsData = mdmsUtil.fetchMdmsData(request.getRequestInfo(), rootTenantId, MDMS_PLAN_ASSUMPTION_MODULE_NAME, Collections.singletonList(MDMS_MASTER_ASSUMPTION)); - final String jsonPathForAssumption = "$." + MDMS_PLAN_ASSUMPTION_MODULE_NAME + "." + MDMS_MASTER_ASSUMPTION + ".*.code"; + final String jsonPathForAssumption = "$." + MDMS_PLAN_ASSUMPTION_MODULE_NAME + "." + MDMS_MASTER_ASSUMPTION + ".*"; List assumptionListFromMDMS = null; try { diff --git a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java index 131bcf71afc..8af03a3e0a9 100644 --- a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java @@ -2,13 +2,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; import digit.config.Configuration; +import java.util.LinkedList; import lombok.extern.slf4j.Slf4j; import org.egov.common.contract.request.RequestInfo; import org.egov.mdms.model.*; -import org.json.JSONArray; +import org.egov.tracer.model.CustomException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; import org.springframework.web.client.RestTemplate; import java.util.ArrayList; @@ -32,10 +34,10 @@ public class MdmsUtil { private Configuration configs; - public Object fetchMdmsData(RequestInfo requestInfo, String tenantId, String moduleName, List masterNameList) { + public Object fetchMdmsData(RequestInfo requestInfo, String tenantId) { StringBuilder uri = new StringBuilder(); uri.append(configs.getMdmsHost()).append(configs.getMdmsEndPoint()); - MdmsCriteriaReq mdmsCriteriaReq = getMdmsRequest(requestInfo, tenantId, moduleName, masterNameList); + MdmsCriteriaReq mdmsCriteriaReq = getMdmsRequest(requestInfo, tenantId); Object response = new HashMap<>(); MdmsResponse mdmsResponse = new MdmsResponse(); try { @@ -45,31 +47,46 @@ public Object fetchMdmsData(RequestInfo requestInfo, String tenantId, String mod log.error(ERROR_WHILE_FETCHING_FROM_MDMS, e); } - return mdmsResponse.getMdmsRes(); + Object result = mdmsResponse.getMdmsRes(); + if (result == null || ObjectUtils.isEmpty(result)) { + log.error(NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_MESSAGE + " - " + tenantId); + throw new CustomException(NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_CODE, NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_MESSAGE); + } + return result; } - private MdmsCriteriaReq getMdmsRequest(RequestInfo requestInfo, String tenantId, String moduleName, List masterNameList) { - List masterDetailList = new ArrayList<>(); - for (String masterName : masterNameList) { - MasterDetail masterDetail = new MasterDetail(); - masterDetail.setName(masterName); - masterDetailList.add(masterDetail); - } + public MdmsCriteriaReq getMdmsRequest(RequestInfo requestInfo, String tenantId) { + + ModuleDetail tenantModuleDetail = getTenantModuleRequestData(); + ModuleDetail assumptionModuleDetail = getAssumptionModuleDetail(); + + List moduleDetails = new LinkedList<>(); + moduleDetails.add(tenantModuleDetail); + moduleDetails.add(assumptionModuleDetail); + + MdmsCriteria mdmsCriteria = MdmsCriteria.builder().moduleDetails(moduleDetails).tenantId(tenantId).build(); + + return MdmsCriteriaReq.builder().mdmsCriteria(mdmsCriteria).requestInfo(requestInfo).build(); + } - ModuleDetail moduleDetail = new ModuleDetail(); - moduleDetail.setMasterDetails(masterDetailList); - moduleDetail.setModuleName(moduleName); - List moduleDetailList = new ArrayList<>(); - moduleDetailList.add(moduleDetail); + private ModuleDetail getTenantModuleRequestData() { + List tenantMasterDetails = new ArrayList<>(); - MdmsCriteria mdmsCriteria = new MdmsCriteria(); - mdmsCriteria.setTenantId(tenantId.split("\\.")[0]); - mdmsCriteria.setModuleDetails(moduleDetailList); + MasterDetail tenantMasterDetail = MasterDetail.builder().name(MDSM_MASTER_TENANTS).filter(FILTER_CODE).build(); - MdmsCriteriaReq mdmsCriteriaReq = new MdmsCriteriaReq(); - mdmsCriteriaReq.setMdmsCriteria(mdmsCriteria); - mdmsCriteriaReq.setRequestInfo(requestInfo); + tenantMasterDetails.add(tenantMasterDetail); - return mdmsCriteriaReq; + return ModuleDetail.builder().masterDetails(tenantMasterDetails).moduleName(MDMS_TENANT_MODULE_NAME).build(); } + + private ModuleDetail getAssumptionModuleDetail() { + List assumptionMasterDetails = new ArrayList<>(); + + MasterDetail assumptionMasterDetail = MasterDetail.builder().name(MDMS_MASTER_ASSUMPTION).filter(FILTER_CODE).build(); + + assumptionMasterDetails.add(assumptionMasterDetail); + + return ModuleDetail.builder().masterDetails(assumptionMasterDetails).moduleName(MDMS_PLAN_ASSUMPTION_MODULE_NAME).build(); + } + } \ No newline at end of file diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java index 802f62aaef8..5bd40211aa0 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java @@ -1,6 +1,7 @@ package digit.web.models; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.NotEmpty; import java.util.ArrayList; import java.util.List; import jakarta.validation.Valid; @@ -44,21 +45,25 @@ public class PlanConfiguration { @JsonProperty("files") @NotNull + @NotEmpty @Valid private List files = new ArrayList<>(); @JsonProperty("assumptions") @NotNull + @NotEmpty @Valid private List assumptions = new ArrayList<>(); @JsonProperty("operations") @NotNull + @NotEmpty @Valid private List operations = new ArrayList<>(); @JsonProperty("resourceMapping") @NotNull + @NotEmpty @Valid private List resourceMapping = new ArrayList<>(); diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java index 7dbb516e1d3..47e8727c52c 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java @@ -1,5 +1,6 @@ package digit.web.models; +import jakarta.validation.Valid; import jakarta.validation.constraints.Size; import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.validation.annotation.Validated; @@ -36,6 +37,4 @@ public class PlanConfigurationSearchCriteria { @JsonProperty("limit") private Integer limit; - - } From 66dba87ef1ad6465e6f1460788a56f8e2d2569b8 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 13 Mar 2024 17:06:28 +0530 Subject: [PATCH 31/53] HLM-5116 added tenantId related validations --- .../validator/PlanConfigurationValidator.java | 21 ------------------- .../src/main/java/digit/util/MdmsUtil.java | 12 ----------- 2 files changed, 33 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index 2dc961fba4c..06af2116509 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -49,31 +49,10 @@ public void validateCreate(PlanConfigurationRequest request) { String rootTenantId = planConfiguration.getTenantId().split("\\.")[0]; Object mdmsData = mdmsUtil.fetchMdmsData(request.getRequestInfo(), rootTenantId); - validateTenantId(request, mdmsData); validateAssumptionKeyAgainstMDMS(request, mdmsData); validateAssumptionValue(planConfiguration); } - public void validateTenantId(PlanConfigurationRequest request, Object mdmsData) { - PlanConfiguration planConfiguration = request.getPlanConfiguration(); - final String jsonPathForTenant = "$." + MDMS_TENANT_MODULE_NAME + "." + MDSM_MASTER_TENANTS + ".*"; - - List tenantListFromMDMS = null; - try { - log.info(jsonPathForTenant); - tenantListFromMDMS = JsonPath.read(mdmsData, jsonPathForTenant); - } catch (Exception e) { - log.error(e.getMessage()); - throw new CustomException("JSONPATH_ERROR", "Failed to parse mdms response"); - } - - if (!tenantListFromMDMS.contains(planConfiguration.getTenantId())) { - log.error("The tenant: " + planConfiguration.getTenantId() + " is not present in MDMS"); - throw new CustomException(TENANT_NOT_FOUND_IN_MDMS_CODE, TENANT_NOT_FOUND_IN_MDMS_MESSAGE); - } - - } - public void validateAssumptionValue(PlanConfiguration planConfiguration) { Set assumptionValues = planConfiguration.getAssumptions().stream() .map(Assumption::getKey) diff --git a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java index 8af03a3e0a9..eb1bdb77bea 100644 --- a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java @@ -57,11 +57,9 @@ public Object fetchMdmsData(RequestInfo requestInfo, String tenantId) { public MdmsCriteriaReq getMdmsRequest(RequestInfo requestInfo, String tenantId) { - ModuleDetail tenantModuleDetail = getTenantModuleRequestData(); ModuleDetail assumptionModuleDetail = getAssumptionModuleDetail(); List moduleDetails = new LinkedList<>(); - moduleDetails.add(tenantModuleDetail); moduleDetails.add(assumptionModuleDetail); MdmsCriteria mdmsCriteria = MdmsCriteria.builder().moduleDetails(moduleDetails).tenantId(tenantId).build(); @@ -69,16 +67,6 @@ public MdmsCriteriaReq getMdmsRequest(RequestInfo requestInfo, String tenantId) return MdmsCriteriaReq.builder().mdmsCriteria(mdmsCriteria).requestInfo(requestInfo).build(); } - private ModuleDetail getTenantModuleRequestData() { - List tenantMasterDetails = new ArrayList<>(); - - MasterDetail tenantMasterDetail = MasterDetail.builder().name(MDSM_MASTER_TENANTS).filter(FILTER_CODE).build(); - - tenantMasterDetails.add(tenantMasterDetail); - - return ModuleDetail.builder().masterDetails(tenantMasterDetails).moduleName(MDMS_TENANT_MODULE_NAME).build(); - } - private ModuleDetail getAssumptionModuleDetail() { List assumptionMasterDetails = new ArrayList<>(); From 00f7a874ca5e33abafca64953d14ca0ee7499a92 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Fri, 15 Mar 2024 13:09:26 +0530 Subject: [PATCH 32/53] HLM-5121 adding changes for update API --- .../service/PlanConfigurationService.java | 15 ++++++ .../service/enrichment/EnrichmentService.java | 49 ++++++++++++++++--- .../validator/PlanConfigurationValidator.java | 36 ++++++++++++-- .../web/controllers/PlanConfigController.java | 3 +- 4 files changed, 91 insertions(+), 12 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java index 29e36745a0e..8ac4df488e2 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java @@ -8,9 +8,12 @@ import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; +import digit.web.models.PlanConfigurationResponse; import digit.web.models.PlanConfigurationSearchRequest; +import java.util.Collections; import java.util.List; import lombok.extern.slf4j.Slf4j; +import org.egov.common.utils.ResponseInfoUtil; import org.springframework.stereotype.Service; @Service @@ -47,4 +50,16 @@ public List search(PlanConfigurationSearchRequest request) { validator.validateSearchRequest(request); return repository.search(request.getPlanConfigurationSearchCriteria()); } + + public PlanConfigurationResponse update(PlanConfigurationRequest request) { + validator.validateUpdateRequest(request); + enrichmentService.enrichUpdate(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())) + .build(); + } } \ No newline at end of file diff --git a/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java b/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java index 14ee802dc3e..7348de5e061 100644 --- a/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java @@ -1,16 +1,9 @@ package digit.service.enrichment; import digit.config.Configuration; -import digit.web.models.Assumption; -import digit.web.models.File; -import digit.web.models.Operation; import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; -import digit.web.models.ResourceMapping; -import java.util.List; -import java.util.UUID; import lombok.extern.slf4j.Slf4j; -import org.egov.common.contract.models.AuditDetails; import org.egov.common.utils.AuditDetailsEnrichmentUtil; import org.egov.common.utils.UUIDEnrichmentUtil; import org.egov.tracer.model.CustomException; @@ -18,7 +11,7 @@ import static digit.config.ServiceConstants.USERINFO_MISSING_CODE; import static digit.config.ServiceConstants.USERINFO_MISSING_MESSAGE; - +import org.springframework.util.ObjectUtils; @Component @Slf4j @@ -63,4 +56,44 @@ public void enrichAuditDetails(PlanConfigurationRequest request, Boolean isCreat .prepareAuditDetails(planConfiguration.getAuditDetails(), request.getRequestInfo(), isCreate)); } + public void enrichUpdate(PlanConfigurationRequest request) { + enrichPlanConfigurationForUpdate(request); + if(request.getRequestInfo().getUserInfo() == null) + throw new CustomException(USERINFO_MISSING_CODE, USERINFO_MISSING_MESSAGE); + + enrichAuditDetails(request, Boolean.FALSE); + } + + public void enrichPlanConfigurationForUpdate(PlanConfigurationRequest request) { + PlanConfiguration planConfiguration = request.getPlanConfiguration(); + + // For Files + planConfiguration.getFiles().forEach(file -> { + if (ObjectUtils.isEmpty(file.getId())) { + UUIDEnrichmentUtil.enrichRandomUuid(file, "id"); + } + }); + + // For Assumptions + planConfiguration.getAssumptions().forEach(assumption -> { + if (ObjectUtils.isEmpty(assumption.getId())) { + UUIDEnrichmentUtil.enrichRandomUuid(assumption, "id"); + } + }); + + // For Operations + planConfiguration.getOperations().forEach(operation -> { + if (ObjectUtils.isEmpty(operation.getId())) { + UUIDEnrichmentUtil.enrichRandomUuid(operation, "id"); + } + }); + + // For ResourceMappings + planConfiguration.getResourceMapping().forEach(resourceMapping -> { + if (ObjectUtils.isEmpty(resourceMapping.getId())) { + UUIDEnrichmentUtil.enrichRandomUuid(resourceMapping, "id"); + } + }); + } + } diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index 06af2116509..e6ea7d5a9bb 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -2,12 +2,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.JsonPath; +import digit.repository.PlanConfigurationRepository; import digit.util.MdmsUtil; import digit.web.models.Assumption; import digit.web.models.Operation; import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; +import digit.web.models.PlanConfigurationSearchCriteria; import digit.web.models.PlanConfigurationSearchRequest; +import digit.web.models.PlanSearchCriteria; import java.util.Collections; import java.util.List; import java.util.Map; @@ -16,9 +19,11 @@ import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.apache.coyote.RequestInfo; import org.egov.tracer.model.CustomException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; import static digit.config.ServiceConstants.ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_CODE; import static digit.config.ServiceConstants.ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_MESSAGE; @@ -37,11 +42,12 @@ public class PlanConfigurationValidator { private MdmsUtil mdmsUtil; - private ObjectMapper objectMapper; - public PlanConfigurationValidator(MdmsUtil mdmsUtil, ObjectMapper objectMapper) { + private PlanConfigurationRepository planConfigRepository; + + public PlanConfigurationValidator(MdmsUtil mdmsUtil, PlanConfigurationRepository planConfigRepository) { this.mdmsUtil = mdmsUtil; - this.objectMapper = objectMapper; + this.planConfigRepository = planConfigRepository; } public void validateCreate(PlanConfigurationRequest request) { @@ -103,4 +109,28 @@ private void validateSearchCriteria(PlanConfigurationSearchRequest planConfigura throw new CustomException("TENANT ID CANNOT BE EMPTY", "Tenant Id cannot be empty, TenantId should be present"); } } + + public void validateUpdateRequest(PlanConfigurationRequest request) { + PlanConfiguration planConfiguration = request.getPlanConfiguration(); + String rootTenantId = planConfiguration.getTenantId().split("\\.")[0]; + Object mdmsData = mdmsUtil.fetchMdmsData(request.getRequestInfo(), rootTenantId); + + // Validate plan existence + validatePlanConfigExistence(request); + + //Validate Assumption keys against MDMS data + validateAssumptionKeyAgainstMDMS(request, mdmsData); + + //Validate Assumption values under operations with assumption keys + validateAssumptionValue(planConfiguration); + } + + public void validatePlanConfigExistence(PlanConfigurationRequest request) { + // If plan id provided is invalid, throw an exception + if(CollectionUtils.isEmpty(planConfigRepository.search(PlanConfigurationSearchCriteria.builder() + .id(request.getPlanConfiguration().getId()) + .build()))) { + throw new CustomException("INVALID_PLAN_CONFIG_ID", "Plan config id provided is invalid"); + } + } } diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java index 48b7684b122..0d2122eedcf 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java @@ -60,6 +60,7 @@ public ResponseEntity configSearchPost(@Parameter(in @RequestMapping(value = "/config/_update", method = RequestMethod.POST) public ResponseEntity configUpdatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationRequest body) { - return ResponseEntity.status(HttpStatus.ACCEPTED).body(new PlanConfigurationResponse()); + PlanConfigurationResponse response = planConfigurationService.update(body); + return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); } } From 51058f831813783dcbbeac6dd2f634989d8ac26c Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Fri, 15 Mar 2024 16:44:28 +0530 Subject: [PATCH 33/53] HLM-5121 adding code comments --- .../impl/PlanConfigurationRepositoryImpl.java | 17 ++++++++-- .../service/PlanConfigurationService.java | 15 ++++++++ .../service/enrichment/EnrichmentService.java | 34 ++++++++++++++++--- .../validator/PlanConfigurationValidator.java | 25 ++++++++++++++ .../web/controllers/PlanConfigController.java | 15 ++++++++ 5 files changed, 99 insertions(+), 7 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java index 8e18b15bf41..9fdfe0a4f25 100644 --- a/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java @@ -37,11 +37,20 @@ public PlanConfigurationRepositoryImpl(Producer producer, JdbcTemplate jdbcTempl this.planConfigRowMapper = planConfigRowMapper; } + /** + * Pushes a new plan configuration to persister kafka topic. + * @param planConfigurationRequest The request containing the plan configuration details. + */ @Override public void create(PlanConfigurationRequest planConfigurationRequest) { - producer.push(config.getPlanConfigCreateTopic(),planConfigurationRequest); + producer.push(config.getPlanConfigCreateTopic(), planConfigurationRequest); } + /** + * Searches for plan configurations based on the provided search criteria. + * @param planConfigurationSearchCriteria The criteria to use for searching plan configurations. + * @return A list of plan configurations that match the search criteria. + */ @Override public List search(PlanConfigurationSearchCriteria planConfigurationSearchCriteria) { List preparedStmtList = new ArrayList<>(); @@ -51,8 +60,12 @@ public List search(PlanConfigurationSearchCriteria planConfig return jdbcTemplate.query(query, preparedStmtList.toArray(), planConfigRowMapper); } + /** + * Pushes an updated existing plan configuration to persister kafka topic. + * @param planConfigurationRequest The request containing the updated plan configuration details. + */ @Override public void update(PlanConfigurationRequest planConfigurationRequest) { - producer.push(config.getPlanConfigUpdateTopic(),planConfigurationRequest); + producer.push(config.getPlanConfigUpdateTopic(), planConfigurationRequest); } } diff --git a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java index 8ac4df488e2..eb67d0b2738 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java @@ -39,6 +39,11 @@ public PlanConfigurationService(Producer producer, EnrichmentService enrichmentS this.repository = repository; } + /** + * 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. + */ public PlanConfigurationRequest create(PlanConfigurationRequest request) { validator.validateCreate(request); enrichmentService.enrichCreate(request); @@ -46,11 +51,21 @@ public PlanConfigurationRequest create(PlanConfigurationRequest request) { return request; } + /** + * 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 List search(PlanConfigurationSearchRequest request) { validator.validateSearchRequest(request); return repository.search(request.getPlanConfigurationSearchCriteria()); } + /** + * 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. + */ public PlanConfigurationResponse update(PlanConfigurationRequest request) { validator.validateUpdateRequest(request); enrichmentService.enrichUpdate(request); diff --git a/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java b/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java index 7348de5e061..7f7d445b904 100644 --- a/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/EnrichmentService.java @@ -22,16 +22,26 @@ public EnrichmentService(Configuration config) { this.config = config; } - public void enrichCreate(PlanConfigurationRequest request) { + /** + * Enriches the PlanConfigurationRequest for creating a new plan configuration. + * This method enriches the plan configuration with generated IDs, 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. + */ + public void enrichCreate(PlanConfigurationRequest request) { enrichPlanConfiguration(request.getPlanConfiguration()); - if(request.getRequestInfo().getUserInfo() == null) + if (request.getRequestInfo().getUserInfo() == null) throw new CustomException(USERINFO_MISSING_CODE, USERINFO_MISSING_MESSAGE); enrichAuditDetails(request, Boolean.TRUE); } + /** + * Enriches the given plan configuration with generated IDs for plan, files, assumptions, operations, and resource mappings. + * @param planConfiguration The PlanConfiguration to be enriched. + */ public void enrichPlanConfiguration(PlanConfiguration planConfiguration) { - log.info("enriching plan config with generated IDs"); + log.info("Enriching plan config with generated IDs"); // Generate id for plan configuration UUIDEnrichmentUtil.enrichRandomUuid(planConfiguration, "id"); @@ -49,21 +59,35 @@ public void enrichPlanConfiguration(PlanConfiguration planConfiguration) { planConfiguration.getResourceMapping().forEach(resourceMapping -> UUIDEnrichmentUtil.enrichRandomUuid(resourceMapping, "id")); } + /** + * Enriches the audit details for the PlanConfigurationRequest based on the operation type (create or update). + * @param request The PlanConfigurationRequest for which audit details are to be enriched. + * @param isCreate A boolean indicating whether the operation is a create or update operation. + */ public void enrichAuditDetails(PlanConfigurationRequest request, Boolean isCreate) { - // Enrich audit details for plan configurationqq PlanConfiguration planConfiguration = request.getPlanConfiguration(); planConfiguration.setAuditDetails(AuditDetailsEnrichmentUtil .prepareAuditDetails(planConfiguration.getAuditDetails(), request.getRequestInfo(), isCreate)); } + /** + * 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) { enrichPlanConfigurationForUpdate(request); - if(request.getRequestInfo().getUserInfo() == null) + if (request.getRequestInfo().getUserInfo() == null) throw new CustomException(USERINFO_MISSING_CODE, USERINFO_MISSING_MESSAGE); enrichAuditDetails(request, Boolean.FALSE); } + /** + * Enriches the plan configuration for update by generating IDs for files, assumptions, operations, and resource mappings if they are empty. + * @param request The PlanConfigurationRequest to be enriched for update operation. + */ public void enrichPlanConfigurationForUpdate(PlanConfigurationRequest request) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index e6ea7d5a9bb..b0cec953b7c 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -50,6 +50,10 @@ public PlanConfigurationValidator(MdmsUtil mdmsUtil, PlanConfigurationRepository this.planConfigRepository = planConfigRepository; } + /** + * Validates the create request for plan configuration, including assumptions against MDMS data. + * @param request The create request for plan configuration. + */ public void validateCreate(PlanConfigurationRequest request) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); String rootTenantId = planConfiguration.getTenantId().split("\\.")[0]; @@ -59,6 +63,10 @@ public void validateCreate(PlanConfigurationRequest request) { validateAssumptionValue(planConfiguration); } + /** + * Validates the assumption values against the assumption keys in the plan configuration. + * @param planConfiguration The plan configuration to validate. + */ public void validateAssumptionValue(PlanConfiguration planConfiguration) { Set assumptionValues = planConfiguration.getAssumptions().stream() .map(Assumption::getKey) @@ -73,6 +81,11 @@ public void validateAssumptionValue(PlanConfiguration planConfiguration) { } } + /** + * Validates the assumption keys against MDMS data. + * @param request The request containing the plan configuration and the MDMS data. + * @param mdmsData The MDMS data. + */ public void validateAssumptionKeyAgainstMDMS(PlanConfigurationRequest request, Object mdmsData) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); final String jsonPathForAssumption = "$." + MDMS_PLAN_ASSUMPTION_MODULE_NAME + "." + MDMS_MASTER_ASSUMPTION + ".*"; @@ -96,6 +109,10 @@ public void validateAssumptionKeyAgainstMDMS(PlanConfigurationRequest request, O } } + /** + * Validates the search request for plan configurations. + * @param planConfigurationSearchRequest The search request for plan configurations. + */ public void validateSearchRequest(PlanConfigurationSearchRequest planConfigurationSearchRequest) { validateSearchCriteria(planConfigurationSearchRequest); } @@ -110,6 +127,10 @@ private void validateSearchCriteria(PlanConfigurationSearchRequest planConfigura } } + /** + * Validates the update request for plan configuration, including assumptions against MDMS data. + * @param request The update request for plan configuration. + */ public void validateUpdateRequest(PlanConfigurationRequest request) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); String rootTenantId = planConfiguration.getTenantId().split("\\.")[0]; @@ -125,6 +146,10 @@ public void validateUpdateRequest(PlanConfigurationRequest request) { validateAssumptionValue(planConfiguration); } + /** + * Validates the existence of the plan configuration in the repository. + * @param request The request containing the plan configuration to validate. + */ public void validatePlanConfigExistence(PlanConfigurationRequest request) { // If plan id provided is invalid, throw an exception if(CollectionUtils.isEmpty(planConfigRepository.search(PlanConfigurationSearchCriteria.builder() diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java index 0d2122eedcf..60692e1f31c 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java @@ -37,6 +37,11 @@ public PlanConfigController(ObjectMapper objectMapper, PlanConfigurationService this.responseInfoFactory = responseInfoFactory; } + /** + * Request handler for serving plan configuration create requests + * @param body + * @return + */ @RequestMapping(value = "/config/_create", method = RequestMethod.POST) public ResponseEntity configCreatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationRequest body) { @@ -51,6 +56,11 @@ public ResponseEntity configCreatePost(@Parameter(in } + /** + * Request handler for serving plan configuration search requests + * @param body + * @return + */ @RequestMapping(value = "/config/_search", method = RequestMethod.POST) public ResponseEntity configSearchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationSearchRequest body) { List planConfigurationList = planConfigurationService.search(body); @@ -58,6 +68,11 @@ public ResponseEntity configSearchPost(@Parameter(in return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); } + /** + * Request handler for serving plan configuration update requests + * @param body + * @return + */ @RequestMapping(value = "/config/_update", method = RequestMethod.POST) public ResponseEntity configUpdatePost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationRequest body) { PlanConfigurationResponse response = planConfigurationService.update(body); From d46760a005deaecbcaa190ba493de135bf90588e Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 27 Mar 2024 12:58:38 +0530 Subject: [PATCH 34/53] HLM-5535 changes for field validations --- .../src/main/java/digit/web/models/Assumption.java | 6 ++++++ .../plan-service/src/main/java/digit/web/models/File.java | 2 ++ .../src/main/java/digit/web/models/PlanConfiguration.java | 3 +++ 3 files changed, 11 insertions(+) diff --git a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java index b8c6e915351..374a3e0fc9e 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java @@ -7,6 +7,9 @@ import org.springframework.validation.annotation.Validated; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import jakarta.validation.constraints.DecimalMax; +import jakarta.validation.constraints.DecimalMin; +import jakarta.validation.constraints.Digits; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.Data; @@ -34,6 +37,9 @@ public class Assumption { @JsonProperty("value") @NotNull @Valid + @DecimalMin(value = "0.01", inclusive = true, message = "Assumption value must be greater than 0") + @DecimalMax(value = "999.99", inclusive = true, message = "Assumption value must be less than 1000") + @Digits(integer = 3, fraction = 2, message = "Value must have up to 3 digits and up to 2 decimal points") private BigDecimal value = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/File.java b/health-services/plan-service/src/main/java/digit/web/models/File.java index 9d06c9d866f..1aa5fad4f22 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/File.java +++ b/health-services/plan-service/src/main/java/digit/web/models/File.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; import jakarta.validation.Valid; @@ -29,6 +30,7 @@ public class File { @JsonProperty("filestoreId") @NotNull @Size(min = 1, max = 128) + @Pattern(regexp = "^(?!\\p{Punct}+$).*$", message = "Filestore Id must not contain only special characters") private String filestoreId = null; @JsonProperty("inputFileType") diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java index 5bd40211aa0..6959f0689c2 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java @@ -7,6 +7,7 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import jakarta.validation.constraints.Pattern; import org.egov.common.contract.models.AuditDetails; import org.springframework.validation.annotation.Validated; import lombok.AllArgsConstructor; @@ -36,11 +37,13 @@ public class PlanConfiguration { @JsonProperty("name") @NotNull @Size(min = 2, max = 128) + @Pattern(regexp = "^(?!\\p{Punct}+$).*$", message = "Name must not contain only special characters") private String name = null; @JsonProperty("executionPlanId") @NotNull @Size(min = 2, max = 64) + @Pattern(regexp = "^(?!\\p{Punct}+$).*$", message = "Execution Plan Id must not contain only special characters") private String executionPlanId = null; @JsonProperty("files") From b05bf7e60b24510bf10473b12bd73cfc21e03f56 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Mon, 1 Apr 2024 10:37:03 +0530 Subject: [PATCH 35/53] HLM-5116 changing response status. --- .../main/java/digit/web/controllers/PlanConfigController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java index 60692e1f31c..4db42785b3f 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java @@ -65,7 +65,7 @@ public ResponseEntity configCreatePost(@Parameter(in public ResponseEntity configSearchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationSearchRequest body) { List planConfigurationList = planConfigurationService.search(body); PlanConfigurationResponse response = PlanConfigurationResponse.builder().responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(body.getRequestInfo(), true)).planConfiguration(planConfigurationList).build(); - return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); + return ResponseEntity.status(HttpStatus.OK).body(response); } /** From 925306d71d6647afd3a624db65f68c6818bd8a26 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 4 Apr 2024 13:52:37 +0530 Subject: [PATCH 36/53] HLM-5117 adding changes for resource mapping filestore id and search by useruuid --- .../java/digit/config/ServiceConstants.java | 3 +++ .../querybuilder/PlanConfigQueryBuilder.java | 8 +++++- .../rowmapper/PlanConfigRowMapper.java | 1 + .../validator/PlanConfigurationValidator.java | 27 +++++++++++++++++++ .../PlanConfigurationSearchCriteria.java | 3 +++ .../digit/web/models/ResourceMapping.java | 7 +++++ .../src/main/resources/application.properties | 2 +- ...plan_configuration_add_filestoreid_ddl.sql | 1 + 8 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 health-services/plan-service/src/main/resources/db/migration/main/V20240404113045__plan_configuration_add_filestoreid_ddl.sql diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index 1cb0a0169bb..c4f7e3bc765 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -52,6 +52,9 @@ public class ServiceConstants { public static final String ASSUMPTION_VALUE_NOT_FOUND_CODE = "ASSUMPTION_VALUE_NOT_FOUND"; public static final String ASSUMPTION_VALUE_NOT_FOUND_MESSAGE = "Operation's Assumption value not found in assumptions list "; + public static final String FILESTORE_ID_INVALID_CODE = "FILESTORE_ID_INVALID"; + public static final String FILESTORE_ID_INVALID_MESSAGE = "Resource mapping does not have a Valid File Store Id "; + public static final String ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_CODE = "ASSUMPTION_KEY_NOT_FOUND_IN_MDMS"; public static final String ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_MESSAGE = "Assumption Key is not present in MDMS"; diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java index b44dc7fe862..2c24a81270d 100644 --- a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java @@ -21,7 +21,7 @@ public PlanConfigQueryBuilder(Configuration config) { "\t pcf.id as plan_configuration_files_id, pcf.plan_configuration_id as plan_configuration_files_plan_configuration_id, pcf.filestore_id as plan_configuration_files_filestore_id, pcf.input_file_type as plan_configuration_files_input_file_type, pcf.created_by as plan_configuration_files_created_by, pcf.created_time as plan_configuration_files_created_time, pcf.last_modified_by as plan_configuration_files_last_modified_by, pcf.last_modified_time as plan_configuration_files_last_modified_time,\n" + "\t pca.id as plan_configuration_assumptions_id, pca.key as plan_configuration_assumptions_key, pca.value as plan_configuration_assumptions_value, pca.plan_configuration_id as plan_configuration_assumptions_plan_configuration_id, pca.created_by as plan_configuration_assumptions_created_by, pca.created_time as plan_configuration_assumptions_created_time, pca.last_modified_by as plan_configuration_assumptions_last_modified_by, pca.last_modified_time as plan_configuration_assumptions_last_modified_time,\n" + "\t pco.id as plan_configuration_operations_id, pco.input as plan_configuration_operations_input, pco.operator as plan_configuration_operations_operator, pco.assumption_value as plan_configuration_operations_assumption_value, pco.output as plan_configuration_operations_output, pco.plan_configuration_id as plan_configuration_operations_plan_configuration_id, pco.created_by as plan_configuration_operations_created_by, pco.created_time as plan_configuration_operations_created_time, pco.last_modified_by as plan_configuration_operations_last_modified_by, pco.last_modified_time as plan_configuration_operations_last_modified_time,\n" + - "\t pcm.id as plan_configuration_mapping_id, pcm.mapped_from as plan_configuration_mapping_mapped_from, pcm.mapped_to as plan_configuration_mapping_mapped_to, pcm.plan_configuration_id as plan_configuration_mapping_plan_configuration_id, pcm.created_by as plan_configuration_mapping_created_by, pcm.created_time as plan_configuration_mapping_created_time, pcm.last_modified_by as plan_configuration_mapping_last_modified_by, pcm.last_modified_time as plan_configuration_mapping_last_modified_time\n" + + "\t pcm.id as plan_configuration_mapping_id, pcm.filestore_id as plan_configuration_mapping_filestore_id, pcm.mapped_from as plan_configuration_mapping_mapped_from, pcm.mapped_to as plan_configuration_mapping_mapped_to, pcm.plan_configuration_id as plan_configuration_mapping_plan_configuration_id, pcm.created_by as plan_configuration_mapping_created_by, pcm.created_time as plan_configuration_mapping_created_time, pcm.last_modified_by as plan_configuration_mapping_last_modified_by, pcm.last_modified_time as plan_configuration_mapping_last_modified_time\n" + "\t FROM plan_configuration pc\n" + "\t LEFT JOIN plan_configuration_files pcf ON pc.id = pcf.plan_configuration_id\n" + "\t LEFT JOIN plan_configuration_assumptions pca ON pc.id = pca.plan_configuration_id\n" + @@ -80,6 +80,12 @@ private String buildPlanConfigSearchQuery(PlanConfigurationSearchCriteria criter preparedStmtList.add(criteria.getName()); } + if (criteria.getUserUuid() != null) { + addClauseIfRequired(preparedStmtList, builder); + builder.append(" pc.created_by = ?"); + preparedStmtList.add(criteria.getUserUuid()); + } + return builder.toString(); } diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java index fcb0f046a04..27d514ebb24 100644 --- a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java @@ -172,6 +172,7 @@ private void addResourceMappings(ResultSet rs, PlanConfiguration planConfigEntry ResourceMapping mapping = new ResourceMapping(); mapping.setId(mappingId); + mapping.setFilestoreId(rs.getString("plan_configuration_mapping_filestore_id")); mapping.setMappedFrom(rs.getString("plan_configuration_mapping_mapped_from")); mapping.setMappedTo(rs.getString("plan_configuration_mapping_mapped_to")); diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index b0cec953b7c..e671f693aac 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -5,12 +5,14 @@ import digit.repository.PlanConfigurationRepository; import digit.util.MdmsUtil; import digit.web.models.Assumption; +import digit.web.models.File; import digit.web.models.Operation; import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; import digit.web.models.PlanConfigurationSearchCriteria; import digit.web.models.PlanConfigurationSearchRequest; import digit.web.models.PlanSearchCriteria; +import digit.web.models.ResourceMapping; import java.util.Collections; import java.util.List; import java.util.Map; @@ -29,6 +31,8 @@ import static digit.config.ServiceConstants.ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_MESSAGE; import static digit.config.ServiceConstants.ASSUMPTION_VALUE_NOT_FOUND_CODE; import static digit.config.ServiceConstants.ASSUMPTION_VALUE_NOT_FOUND_MESSAGE; +import static digit.config.ServiceConstants.FILESTORE_ID_INVALID_CODE; +import static digit.config.ServiceConstants.FILESTORE_ID_INVALID_MESSAGE; import static digit.config.ServiceConstants.MDMS_MASTER_ASSUMPTION; import static digit.config.ServiceConstants.MDMS_PLAN_ASSUMPTION_MODULE_NAME; import static digit.config.ServiceConstants.MDMS_TENANT_MODULE_NAME; @@ -61,6 +65,7 @@ public void validateCreate(PlanConfigurationRequest request) { validateAssumptionKeyAgainstMDMS(request, mdmsData); validateAssumptionValue(planConfiguration); + validateFilestoreId(planConfiguration); } /** @@ -109,6 +114,24 @@ public void validateAssumptionKeyAgainstMDMS(PlanConfigurationRequest request, O } } + /** + * Validates the file store IDs in the provided PlanConfiguration's Resource Mapping list. + * @param planConfiguration The PlanConfiguration to validate. + */ + public void validateFilestoreId(PlanConfiguration planConfiguration) { + Set fileStoreIds = planConfiguration.getFiles().stream() + .map(File::getFilestoreId) + .collect(Collectors.toSet()); + + List resourceMappingList = planConfiguration.getResourceMapping(); + for (ResourceMapping mapping : resourceMappingList) { + if (!fileStoreIds.contains(mapping.getFilestoreId())) { + log.error("Resource Mapping " + mapping.getMappedTo() + " does not have valid fileStoreId " + mapping.getFilestoreId()); + throw new CustomException(FILESTORE_ID_INVALID_CODE, FILESTORE_ID_INVALID_MESSAGE); + } + } + } + /** * Validates the search request for plan configurations. * @param planConfigurationSearchRequest The search request for plan configurations. @@ -144,6 +167,10 @@ public void validateUpdateRequest(PlanConfigurationRequest request) { //Validate Assumption values under operations with assumption keys validateAssumptionValue(planConfiguration); + + //Validate Resource Mapping's Filestore Ids + validateFilestoreId(planConfiguration); + } /** diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java index 47e8727c52c..743e712035b 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java @@ -31,6 +31,9 @@ public class PlanConfigurationSearchCriteria { @JsonProperty("executionPlanId") private String executionPlanId = null; + @JsonProperty("userUuid") + private String userUuid = null; + @JsonProperty("offset") private Integer offset; diff --git a/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java index 7f561b7e50b..a290918099d 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java +++ b/health-services/plan-service/src/main/java/digit/web/models/ResourceMapping.java @@ -4,6 +4,7 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Size; import org.springframework.validation.annotation.Validated; import lombok.AllArgsConstructor; @@ -24,6 +25,12 @@ public class ResourceMapping { @Valid private String id = null; + @JsonProperty("filestoreId") + @NotNull + @Size(min = 1, max = 128) + @Pattern(regexp = "^(?!\\p{Punct}+$).*$", message = "Filestore Id must not contain only special characters") + private String filestoreId = null; + @JsonProperty("mappedFrom") @NotNull @Size(min = 2, max = 256) diff --git a/health-services/plan-service/src/main/resources/application.properties b/health-services/plan-service/src/main/resources/application.properties index ca7f10f4982..9695b36c299 100644 --- a/health-services/plan-service/src/main/resources/application.properties +++ b/health-services/plan-service/src/main/resources/application.properties @@ -71,4 +71,4 @@ kafka.topics.consumer=service-consumer-topic # Pagination config plan.default.offset=0 -plan.default.limit=10 \ No newline at end of file +plan.default.limit=100 \ No newline at end of file diff --git a/health-services/plan-service/src/main/resources/db/migration/main/V20240404113045__plan_configuration_add_filestoreid_ddl.sql b/health-services/plan-service/src/main/resources/db/migration/main/V20240404113045__plan_configuration_add_filestoreid_ddl.sql new file mode 100644 index 00000000000..fcd7cfe2bbc --- /dev/null +++ b/health-services/plan-service/src/main/resources/db/migration/main/V20240404113045__plan_configuration_add_filestoreid_ddl.sql @@ -0,0 +1 @@ +ALTER TABLE plan_configuration_mapping ADD filestore_id character varying(128); From 600b7e5d8cd503d68bc95e6cc2437f3470ea8791 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 4 Apr 2024 16:15:41 +0530 Subject: [PATCH 37/53] HLM-5607 changes for adding template identifier to file --- .../java/digit/config/ServiceConstants.java | 24 +++++-- .../querybuilder/PlanConfigQueryBuilder.java | 2 +- .../rowmapper/PlanConfigRowMapper.java | 2 +- .../validator/PlanConfigurationValidator.java | 67 ++++++++++++++----- .../src/main/java/digit/util/MdmsUtil.java | 9 +-- .../src/main/java/digit/web/models/File.java | 6 ++ ...figuration_add_template_identifier_ddl.sql | 1 + 7 files changed, 85 insertions(+), 26 deletions(-) create mode 100644 health-services/plan-service/src/main/resources/db/migration/main/V20240404150000__plan_configuration_add_template_identifier_ddl.sql diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index c4f7e3bc765..d7dd74a0c26 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -10,9 +10,6 @@ public class ServiceConstants { public static final String EXTERNAL_SERVICE_EXCEPTION = "External Service threw an Exception: "; public static final String SEARCHER_SERVICE_EXCEPTION = "Exception while fetching from searcher: "; - public static final String IDGEN_ERROR = "IDGEN ERROR"; - public static final String NO_IDS_FOUND_ERROR = "No ids returned from idgen Service"; - public static final String ERROR_WHILE_FETCHING_FROM_MDMS = "Exception occurred while fetching category lists from mdms: "; public static final String RES_MSG_ID = "uief87324"; @@ -58,14 +55,31 @@ public class ServiceConstants { public static final String ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_CODE = "ASSUMPTION_KEY_NOT_FOUND_IN_MDMS"; public static final String ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_MESSAGE = "Assumption Key is not present in MDMS"; + public static final String TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS_CODE = "TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS"; + public static final String TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS_MESSAGE = "Template Identifier is not present in MDMS"; + public static final String TENANT_NOT_FOUND_IN_MDMS_CODE = "TENANT_ID_NOT_FOUND_IN_MDMS"; public static final String TENANT_NOT_FOUND_IN_MDMS_MESSAGE = "Tenant Id is not present in MDMS"; + public static final String TENANT_ID_EMPTY_CODE = "TENANT_ID_EMPTY"; + public static final String TENANT_ID_EMPTY_MESSAGE = "Tenant Id cannot be empty, TenantId should be present"; + public static final String NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_CODE = "NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT"; public static final String NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_MESSAGE = "Invalid or incorrect TenantId. No mdms data found for provided Tenant."; - public static final String MDMS_PLAN_ASSUMPTION_MODULE_NAME = "hcm-microplanning"; + public static final String SEARCH_CRITERIA_EMPTY_CODE = "SEARCH_CRITERIA_EMPTY"; + public static final String SEARCH_CRITERIA_EMPTY_MESSAGE = "Search criteria cannot be empty"; + + public static final String INVALID_PLAN_CONFIG_ID_CODE = "INVALID_PLAN_CONFIG_ID"; + public static final String INVALID_PLAN_CONFIG_ID_MESSAGE = "Plan config id provided is invalid"; + + public static final String JSONPATH_ERROR_CODE = "JSONPATH_ERROR"; + public static final String JSONPATH_ERROR_MESSAGE = "Failed to parse mdms response with given Jsonpath" ; + + public static final String MDMS_PLAN_MODULE_NAME = "hcm-microplanning"; public static final String MDMS_MASTER_ASSUMPTION = "Assumptions"; + public static final String MDMS_MASTER_UPLOAD_CONFIGURATION = "UploadConfiguration"; + public static final String MDSM_MASTER_TENANTS = "tenants"; public static final String MDMS_TENANT_MODULE_NAME = "tenant"; @@ -75,5 +89,7 @@ public class ServiceConstants { public static final String FILTER_CODE = "$.*.code"; + public static final String FILTER_ID = "$.*.id"; + } diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java index 2c24a81270d..ded0241a357 100644 --- a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java @@ -18,7 +18,7 @@ public PlanConfigQueryBuilder(Configuration config) { } private static final String PLAN_CONFIG_BASE_SEARCH_QUERY = "SELECT pc.id as plan_configuration_id, pc.tenant_id as plan_configuration_tenant_id, pc.name as plan_configuration_name, pc.execution_plan_id as plan_configuration_execution_plan_id, pc.created_by as plan_configuration_created_by, pc.created_time as plan_configuration_created_time, pc.last_modified_by as plan_configuration_last_modified_by, pc.last_modified_time as plan_configuration_last_modified_time, \n" + - "\t pcf.id as plan_configuration_files_id, pcf.plan_configuration_id as plan_configuration_files_plan_configuration_id, pcf.filestore_id as plan_configuration_files_filestore_id, pcf.input_file_type as plan_configuration_files_input_file_type, pcf.created_by as plan_configuration_files_created_by, pcf.created_time as plan_configuration_files_created_time, pcf.last_modified_by as plan_configuration_files_last_modified_by, pcf.last_modified_time as plan_configuration_files_last_modified_time,\n" + + "\t pcf.id as plan_configuration_files_id, pcf.plan_configuration_id as plan_configuration_files_plan_configuration_id, pcf.filestore_id as plan_configuration_files_filestore_id, pcf.input_file_type as plan_configuration_files_input_file_type, pcf.template_identifier as plan_configuration_files_template_identifier, pcf.created_by as plan_configuration_files_created_by, pcf.created_time as plan_configuration_files_created_time, pcf.last_modified_by as plan_configuration_files_last_modified_by, pcf.last_modified_time as plan_configuration_files_last_modified_time,\n" + "\t pca.id as plan_configuration_assumptions_id, pca.key as plan_configuration_assumptions_key, pca.value as plan_configuration_assumptions_value, pca.plan_configuration_id as plan_configuration_assumptions_plan_configuration_id, pca.created_by as plan_configuration_assumptions_created_by, pca.created_time as plan_configuration_assumptions_created_time, pca.last_modified_by as plan_configuration_assumptions_last_modified_by, pca.last_modified_time as plan_configuration_assumptions_last_modified_time,\n" + "\t pco.id as plan_configuration_operations_id, pco.input as plan_configuration_operations_input, pco.operator as plan_configuration_operations_operator, pco.assumption_value as plan_configuration_operations_assumption_value, pco.output as plan_configuration_operations_output, pco.plan_configuration_id as plan_configuration_operations_plan_configuration_id, pco.created_by as plan_configuration_operations_created_by, pco.created_time as plan_configuration_operations_created_time, pco.last_modified_by as plan_configuration_operations_last_modified_by, pco.last_modified_time as plan_configuration_operations_last_modified_time,\n" + "\t pcm.id as plan_configuration_mapping_id, pcm.filestore_id as plan_configuration_mapping_filestore_id, pcm.mapped_from as plan_configuration_mapping_mapped_from, pcm.mapped_to as plan_configuration_mapping_mapped_to, pcm.plan_configuration_id as plan_configuration_mapping_plan_configuration_id, pcm.created_by as plan_configuration_mapping_created_by, pcm.created_time as plan_configuration_mapping_created_time, pcm.last_modified_by as plan_configuration_mapping_last_modified_by, pcm.last_modified_time as plan_configuration_mapping_last_modified_time\n" + diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java index 27d514ebb24..825ceebb010 100644 --- a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java @@ -78,7 +78,7 @@ private void addFiles(ResultSet rs, PlanConfiguration planConfigEntry, Map fileList = new ArrayList<>(); fileList.add(file); diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index e671f693aac..93573c82d29 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -1,6 +1,5 @@ package digit.service.validator; -import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.JsonPath; import digit.repository.PlanConfigurationRepository; import digit.util.MdmsUtil; @@ -11,19 +10,14 @@ import digit.web.models.PlanConfigurationRequest; import digit.web.models.PlanConfigurationSearchCriteria; import digit.web.models.PlanConfigurationSearchRequest; -import digit.web.models.PlanSearchCriteria; import digit.web.models.ResourceMapping; -import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.apache.coyote.RequestInfo; import org.egov.tracer.model.CustomException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -33,12 +27,19 @@ import static digit.config.ServiceConstants.ASSUMPTION_VALUE_NOT_FOUND_MESSAGE; import static digit.config.ServiceConstants.FILESTORE_ID_INVALID_CODE; import static digit.config.ServiceConstants.FILESTORE_ID_INVALID_MESSAGE; +import static digit.config.ServiceConstants.INVALID_PLAN_CONFIG_ID_CODE; +import static digit.config.ServiceConstants.INVALID_PLAN_CONFIG_ID_MESSAGE; +import static digit.config.ServiceConstants.JSONPATH_ERROR_CODE; +import static digit.config.ServiceConstants.JSONPATH_ERROR_MESSAGE; import static digit.config.ServiceConstants.MDMS_MASTER_ASSUMPTION; -import static digit.config.ServiceConstants.MDMS_PLAN_ASSUMPTION_MODULE_NAME; -import static digit.config.ServiceConstants.MDMS_TENANT_MODULE_NAME; -import static digit.config.ServiceConstants.MDSM_MASTER_TENANTS; -import static digit.config.ServiceConstants.TENANT_NOT_FOUND_IN_MDMS_CODE; -import static digit.config.ServiceConstants.TENANT_NOT_FOUND_IN_MDMS_MESSAGE; +import static digit.config.ServiceConstants.MDMS_MASTER_UPLOAD_CONFIGURATION; +import static digit.config.ServiceConstants.MDMS_PLAN_MODULE_NAME; +import static digit.config.ServiceConstants.SEARCH_CRITERIA_EMPTY_CODE; +import static digit.config.ServiceConstants.SEARCH_CRITERIA_EMPTY_MESSAGE; +import static digit.config.ServiceConstants.TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS_CODE; +import static digit.config.ServiceConstants.TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS_MESSAGE; +import static digit.config.ServiceConstants.TENANT_ID_EMPTY_CODE; +import static digit.config.ServiceConstants.TENANT_ID_EMPTY_MESSAGE; @Component @Slf4j @@ -66,6 +67,7 @@ public void validateCreate(PlanConfigurationRequest request) { validateAssumptionKeyAgainstMDMS(request, mdmsData); validateAssumptionValue(planConfiguration); validateFilestoreId(planConfiguration); + validateTemplateIdentifierAgainstMDMS(request, mdmsData); } /** @@ -93,7 +95,7 @@ public void validateAssumptionValue(PlanConfiguration planConfiguration) { */ public void validateAssumptionKeyAgainstMDMS(PlanConfigurationRequest request, Object mdmsData) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); - final String jsonPathForAssumption = "$." + MDMS_PLAN_ASSUMPTION_MODULE_NAME + "." + MDMS_MASTER_ASSUMPTION + ".*"; + final String jsonPathForAssumption = "$." + MDMS_PLAN_MODULE_NAME + "." + MDMS_MASTER_ASSUMPTION + ".*"; List assumptionListFromMDMS = null; try { @@ -101,7 +103,7 @@ public void validateAssumptionKeyAgainstMDMS(PlanConfigurationRequest request, O assumptionListFromMDMS = JsonPath.read(mdmsData, jsonPathForAssumption); } catch (Exception e) { log.error(e.getMessage()); - throw new CustomException("JSONPATH_ERROR", "Failed to parse mdms response"); + throw new CustomException(JSONPATH_ERROR_CODE, JSONPATH_ERROR_MESSAGE); } for(Assumption assumption : planConfiguration.getAssumptions()) @@ -132,6 +134,36 @@ public void validateFilestoreId(PlanConfiguration planConfiguration) { } } + /** + * Validates the template identifiers of files in the PlanConfigurationRequest against the list of template identifiers + * obtained from MDMS (Master Data Management System) data. + * + * @param request The PlanConfigurationRequest containing the PlanConfiguration to validate. + * @param mdmsData The MDMS data containing template identifiers to validate against. + */ + public void validateTemplateIdentifierAgainstMDMS(PlanConfigurationRequest request, Object mdmsData) { + PlanConfiguration planConfiguration = request.getPlanConfiguration(); + final String jsonPathForTemplateIdentifier = "$." + MDMS_PLAN_MODULE_NAME + "." + MDMS_MASTER_UPLOAD_CONFIGURATION + ".*"; + + List templateIdentifierListFromMDMS = null; + try { + log.info(jsonPathForTemplateIdentifier); + templateIdentifierListFromMDMS = JsonPath.read(mdmsData, jsonPathForTemplateIdentifier); + } catch (Exception e) { + log.error(e.getMessage()); + throw new CustomException(JSONPATH_ERROR_CODE, JSONPATH_ERROR_MESSAGE); + } + + for(File file : planConfiguration.getFiles()) + { + if(!templateIdentifierListFromMDMS.contains(file.getTemplateIdentifier())) + { + log.error("Template Identifier " + file.getTemplateIdentifier() + " is not present in MDMS"); + throw new CustomException(TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS_CODE, TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS_MESSAGE); + } + } + } + /** * Validates the search request for plan configurations. * @param planConfigurationSearchRequest The search request for plan configurations. @@ -142,11 +174,11 @@ public void validateSearchRequest(PlanConfigurationSearchRequest planConfigurati private void validateSearchCriteria(PlanConfigurationSearchRequest planConfigurationSearchRequest) { if (Objects.isNull(planConfigurationSearchRequest.getPlanConfigurationSearchCriteria())) { - throw new CustomException("SEARCH CRITERIA CANNOT BE EMPTY", "Search criteria cannot be empty"); + throw new CustomException(SEARCH_CRITERIA_EMPTY_CODE, SEARCH_CRITERIA_EMPTY_MESSAGE); } if (StringUtils.isEmpty(planConfigurationSearchRequest.getPlanConfigurationSearchCriteria().getTenantId())) { - throw new CustomException("TENANT ID CANNOT BE EMPTY", "Tenant Id cannot be empty, TenantId should be present"); + throw new CustomException(TENANT_ID_EMPTY_CODE, TENANT_ID_EMPTY_MESSAGE); } } @@ -171,6 +203,9 @@ public void validateUpdateRequest(PlanConfigurationRequest request) { //Validate Resource Mapping's Filestore Ids validateFilestoreId(planConfiguration); + //validate Template Identifier against MDMS data + validateTemplateIdentifierAgainstMDMS(request, mdmsData); + } /** @@ -182,7 +217,7 @@ public void validatePlanConfigExistence(PlanConfigurationRequest request) { if(CollectionUtils.isEmpty(planConfigRepository.search(PlanConfigurationSearchCriteria.builder() .id(request.getPlanConfiguration().getId()) .build()))) { - throw new CustomException("INVALID_PLAN_CONFIG_ID", "Plan config id provided is invalid"); + throw new CustomException(INVALID_PLAN_CONFIG_ID_CODE, INVALID_PLAN_CONFIG_ID_MESSAGE); } } } diff --git a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java index eb1bdb77bea..aaffd8bf840 100644 --- a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java @@ -57,7 +57,7 @@ public Object fetchMdmsData(RequestInfo requestInfo, String tenantId) { public MdmsCriteriaReq getMdmsRequest(RequestInfo requestInfo, String tenantId) { - ModuleDetail assumptionModuleDetail = getAssumptionModuleDetail(); + ModuleDetail assumptionModuleDetail = getPlanModuleDetail(); List moduleDetails = new LinkedList<>(); moduleDetails.add(assumptionModuleDetail); @@ -67,14 +67,15 @@ public MdmsCriteriaReq getMdmsRequest(RequestInfo requestInfo, String tenantId) return MdmsCriteriaReq.builder().mdmsCriteria(mdmsCriteria).requestInfo(requestInfo).build(); } - private ModuleDetail getAssumptionModuleDetail() { + private ModuleDetail getPlanModuleDetail() { List assumptionMasterDetails = new ArrayList<>(); MasterDetail assumptionMasterDetail = MasterDetail.builder().name(MDMS_MASTER_ASSUMPTION).filter(FILTER_CODE).build(); - + MasterDetail uploadConfigMasterDetail = MasterDetail.builder().name(MDMS_MASTER_UPLOAD_CONFIGURATION).filter(FILTER_ID).build(); assumptionMasterDetails.add(assumptionMasterDetail); + assumptionMasterDetails.add(uploadConfigMasterDetail); - return ModuleDetail.builder().masterDetails(assumptionMasterDetails).moduleName(MDMS_PLAN_ASSUMPTION_MODULE_NAME).build(); + return ModuleDetail.builder().masterDetails(assumptionMasterDetails).moduleName(MDMS_PLAN_MODULE_NAME).build(); } } \ No newline at end of file diff --git a/health-services/plan-service/src/main/java/digit/web/models/File.java b/health-services/plan-service/src/main/java/digit/web/models/File.java index 1aa5fad4f22..5e769de4ec7 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/File.java +++ b/health-services/plan-service/src/main/java/digit/web/models/File.java @@ -37,6 +37,12 @@ public class File { @NotNull private InputFileTypeEnum inputFileType = null; + @JsonProperty("templateIdentifier") + @NotNull + @Size(min = 2, max = 128) + @Pattern(regexp = "^(?!\\p{Punct}+$).*$", message = "Name must not contain only special characters") + private String templateIdentifier = null; + /** * The original file type of the Input */ diff --git a/health-services/plan-service/src/main/resources/db/migration/main/V20240404150000__plan_configuration_add_template_identifier_ddl.sql b/health-services/plan-service/src/main/resources/db/migration/main/V20240404150000__plan_configuration_add_template_identifier_ddl.sql new file mode 100644 index 00000000000..e1c67ff2696 --- /dev/null +++ b/health-services/plan-service/src/main/resources/db/migration/main/V20240404150000__plan_configuration_add_template_identifier_ddl.sql @@ -0,0 +1 @@ +ALTER TABLE plan_configuration_files ADD template_identifier character varying(128); From 1f1bc09bc03d98a333df73d3b43ee56722c97f2e Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 4 Apr 2024 17:56:56 +0530 Subject: [PATCH 38/53] HLM-5607 adding validation for useruuid search --- .../java/digit/config/ServiceConstants.java | 4 ++++ .../validator/PlanConfigurationValidator.java | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index d7dd74a0c26..c2c017acead 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -73,6 +73,10 @@ public class ServiceConstants { public static final String INVALID_PLAN_CONFIG_ID_CODE = "INVALID_PLAN_CONFIG_ID"; public static final String INVALID_PLAN_CONFIG_ID_MESSAGE = "Plan config id provided is invalid"; + public static final String REQUEST_UUID_EMPTY_CODE = "REQUEST_UUID_EMPTY"; + public static final String REQUEST_UUID_EMPTY_MESSAGE = "Request UUID is empty"; + public static final String USER_UUID_MISMATCH_CODE = "USER_UUID_MISMATCH"; + public static final String USER_UUID_MISMATCH_MESSAGE = "Not Authorized to search with provided useruuid"; public static final String JSONPATH_ERROR_CODE = "JSONPATH_ERROR"; public static final String JSONPATH_ERROR_MESSAGE = "Failed to parse mdms response with given Jsonpath" ; diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index 93573c82d29..a200b6094f7 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -34,12 +34,16 @@ import static digit.config.ServiceConstants.MDMS_MASTER_ASSUMPTION; import static digit.config.ServiceConstants.MDMS_MASTER_UPLOAD_CONFIGURATION; import static digit.config.ServiceConstants.MDMS_PLAN_MODULE_NAME; +import static digit.config.ServiceConstants.REQUEST_UUID_EMPTY_CODE; +import static digit.config.ServiceConstants.REQUEST_UUID_EMPTY_MESSAGE; import static digit.config.ServiceConstants.SEARCH_CRITERIA_EMPTY_CODE; import static digit.config.ServiceConstants.SEARCH_CRITERIA_EMPTY_MESSAGE; import static digit.config.ServiceConstants.TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS_CODE; import static digit.config.ServiceConstants.TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS_MESSAGE; import static digit.config.ServiceConstants.TENANT_ID_EMPTY_CODE; import static digit.config.ServiceConstants.TENANT_ID_EMPTY_MESSAGE; +import static digit.config.ServiceConstants.USER_UUID_MISMATCH_CODE; +import static digit.config.ServiceConstants.USER_UUID_MISMATCH_MESSAGE; @Component @Slf4j @@ -170,6 +174,7 @@ public void validateTemplateIdentifierAgainstMDMS(PlanConfigurationRequest reque */ public void validateSearchRequest(PlanConfigurationSearchRequest planConfigurationSearchRequest) { validateSearchCriteria(planConfigurationSearchRequest); + validateUserUuid(planConfigurationSearchRequest); } private void validateSearchCriteria(PlanConfigurationSearchRequest planConfigurationSearchRequest) { @@ -182,6 +187,22 @@ private void validateSearchCriteria(PlanConfigurationSearchRequest planConfigura } } + private void validateUserUuid(PlanConfigurationSearchRequest planConfigurationSearchRequest) { + String userUuid = planConfigurationSearchRequest.getPlanConfigurationSearchCriteria().getUserUuid(); + String requestUuid = planConfigurationSearchRequest.getRequestInfo().getUserInfo().getUuid(); + + if (userUuid.isEmpty()) return; + + if (StringUtils.isEmpty(requestUuid)) { + throw new CustomException(REQUEST_UUID_EMPTY_CODE, REQUEST_UUID_EMPTY_MESSAGE); + } + + if (!userUuid.equals(requestUuid)) { + throw new CustomException(USER_UUID_MISMATCH_CODE, USER_UUID_MISMATCH_MESSAGE); + } + } + + /** * Validates the update request for plan configuration, including assumptions against MDMS data. * @param request The update request for plan configuration. From 52572edc4f85e8dfd6748d83126281e15213cee9 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Fri, 5 Apr 2024 12:53:27 +0530 Subject: [PATCH 39/53] HLM-5607 modifying assumptions master --- .../src/main/java/digit/config/ServiceConstants.java | 2 +- .../digit/service/validator/PlanConfigurationValidator.java | 2 +- .../plan-service/src/main/java/digit/util/MdmsUtil.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index c2c017acead..590bf0010c1 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -81,7 +81,7 @@ public class ServiceConstants { public static final String JSONPATH_ERROR_MESSAGE = "Failed to parse mdms response with given Jsonpath" ; public static final String MDMS_PLAN_MODULE_NAME = "hcm-microplanning"; - public static final String MDMS_MASTER_ASSUMPTION = "Assumptions"; + public static final String MDMS_MASTER_ASSUMPTION = "HypothesisAssumptions"; public static final String MDMS_MASTER_UPLOAD_CONFIGURATION = "UploadConfiguration"; public static final String MDSM_MASTER_TENANTS = "tenants"; diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index a200b6094f7..693266849bd 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -99,7 +99,7 @@ public void validateAssumptionValue(PlanConfiguration planConfiguration) { */ public void validateAssumptionKeyAgainstMDMS(PlanConfigurationRequest request, Object mdmsData) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); - final String jsonPathForAssumption = "$." + MDMS_PLAN_MODULE_NAME + "." + MDMS_MASTER_ASSUMPTION + ".*"; + final String jsonPathForAssumption = "$." + MDMS_PLAN_MODULE_NAME + "." + MDMS_MASTER_ASSUMPTION + "[*].assumptions[*]"; List assumptionListFromMDMS = null; try { diff --git a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java index aaffd8bf840..2596a456623 100644 --- a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java @@ -70,7 +70,7 @@ public MdmsCriteriaReq getMdmsRequest(RequestInfo requestInfo, String tenantId) private ModuleDetail getPlanModuleDetail() { List assumptionMasterDetails = new ArrayList<>(); - MasterDetail assumptionMasterDetail = MasterDetail.builder().name(MDMS_MASTER_ASSUMPTION).filter(FILTER_CODE).build(); + MasterDetail assumptionMasterDetail = MasterDetail.builder().name(MDMS_MASTER_ASSUMPTION).build(); MasterDetail uploadConfigMasterDetail = MasterDetail.builder().name(MDMS_MASTER_UPLOAD_CONFIGURATION).filter(FILTER_ID).build(); assumptionMasterDetails.add(assumptionMasterDetail); assumptionMasterDetails.add(uploadConfigMasterDetail); From 65175c19ea212c610438874d7f6204f88b98f778 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Fri, 5 Apr 2024 13:25:58 +0530 Subject: [PATCH 40/53] HLM-5607 modifying assumptions master --- .../digit/service/validator/PlanConfigurationValidator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index 693266849bd..b7455cb9fbc 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -191,7 +191,9 @@ private void validateUserUuid(PlanConfigurationSearchRequest planConfigurationSe String userUuid = planConfigurationSearchRequest.getPlanConfigurationSearchCriteria().getUserUuid(); String requestUuid = planConfigurationSearchRequest.getRequestInfo().getUserInfo().getUuid(); - if (userUuid.isEmpty()) return; + if (userUuid == null || userUuid.isEmpty()) { + return; + } if (StringUtils.isEmpty(requestUuid)) { throw new CustomException(REQUEST_UUID_EMPTY_CODE, REQUEST_UUID_EMPTY_MESSAGE); From ebeecf2aeec3cf2f2f63af6cbb3aca06ddf678b8 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Mon, 15 Apr 2024 14:58:54 +0530 Subject: [PATCH 41/53] HLM-5607 removing useruuid validation --- .../validator/PlanConfigurationValidator.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index b7455cb9fbc..8b627eead3a 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -174,7 +174,6 @@ public void validateTemplateIdentifierAgainstMDMS(PlanConfigurationRequest reque */ public void validateSearchRequest(PlanConfigurationSearchRequest planConfigurationSearchRequest) { validateSearchCriteria(planConfigurationSearchRequest); - validateUserUuid(planConfigurationSearchRequest); } private void validateSearchCriteria(PlanConfigurationSearchRequest planConfigurationSearchRequest) { @@ -187,23 +186,6 @@ private void validateSearchCriteria(PlanConfigurationSearchRequest planConfigura } } - private void validateUserUuid(PlanConfigurationSearchRequest planConfigurationSearchRequest) { - String userUuid = planConfigurationSearchRequest.getPlanConfigurationSearchCriteria().getUserUuid(); - String requestUuid = planConfigurationSearchRequest.getRequestInfo().getUserInfo().getUuid(); - - if (userUuid == null || userUuid.isEmpty()) { - return; - } - - if (StringUtils.isEmpty(requestUuid)) { - throw new CustomException(REQUEST_UUID_EMPTY_CODE, REQUEST_UUID_EMPTY_MESSAGE); - } - - if (!userUuid.equals(requestUuid)) { - throw new CustomException(USER_UUID_MISMATCH_CODE, USER_UUID_MISMATCH_MESSAGE); - } - } - /** * Validates the update request for plan configuration, including assumptions against MDMS data. From 2fbbcac5c1d6475045dfd5fad92f7fd84bd465c1 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 16 Apr 2024 14:10:00 +0530 Subject: [PATCH 42/53] HLM-5607 adding validations for resource mapping and operation --- .../java/digit/config/ServiceConstants.java | 12 ++ .../validator/PlanConfigurationValidator.java | 103 ++++++++++++++++++ .../src/main/java/digit/util/MdmsUtil.java | 2 + 3 files changed, 117 insertions(+) diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index 590bf0010c1..53f58c202d0 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -58,6 +58,14 @@ public class ServiceConstants { public static final String TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS_CODE = "TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS"; public static final String TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS_MESSAGE = "Template Identifier is not present in MDMS"; + public static final String INPUT_KEY_NOT_FOUND_CODE = "INPUT_KEY_NOT_FOUND"; + public static final String INPUT_KEY_NOT_FOUND_MESSAGE = "Operation's Input key not present in MDMS"; + + public static final String LOCALITY_NOT_PRESENT_IN_MAPPED_TO_CODE = "LOCALITY_NOT_PRESENT_IN_MAPPED_TO"; + public static final String LOCALITY_NOT_PRESENT_IN_MAPPED_TO_MESSAGE = "Resource Mapping's MappedTo must contain 'Locality'"; + + public static final String MAPPED_TO_VALIDATION_ERROR_CODE = "MAPPED_TO_VALIDATION_ERROR"; + public static final String TENANT_NOT_FOUND_IN_MDMS_CODE = "TENANT_ID_NOT_FOUND_IN_MDMS"; public static final String TENANT_NOT_FOUND_IN_MDMS_MESSAGE = "Tenant Id is not present in MDMS"; @@ -83,6 +91,7 @@ public class ServiceConstants { public static final String MDMS_PLAN_MODULE_NAME = "hcm-microplanning"; public static final String MDMS_MASTER_ASSUMPTION = "HypothesisAssumptions"; public static final String MDMS_MASTER_UPLOAD_CONFIGURATION = "UploadConfiguration"; + public static final String MDMS_MASTER_RULE_CONFIGURE_INPUTS = "RuleConfigureInputs"; public static final String MDSM_MASTER_TENANTS = "tenants"; public static final String MDMS_TENANT_MODULE_NAME = "tenant"; @@ -95,5 +104,8 @@ public class ServiceConstants { public static final String FILTER_ID = "$.*.id"; + public static final String FILTER_DATA = "$.*.data"; + + public static final String LOCALITY_CODE = "Locality"; } diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index 8b627eead3a..59bdb31a0d2 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -12,6 +12,7 @@ import digit.web.models.PlanConfigurationSearchRequest; import digit.web.models.ResourceMapping; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -27,11 +28,18 @@ import static digit.config.ServiceConstants.ASSUMPTION_VALUE_NOT_FOUND_MESSAGE; import static digit.config.ServiceConstants.FILESTORE_ID_INVALID_CODE; import static digit.config.ServiceConstants.FILESTORE_ID_INVALID_MESSAGE; +import static digit.config.ServiceConstants.INPUT_KEY_NOT_FOUND_CODE; +import static digit.config.ServiceConstants.INPUT_KEY_NOT_FOUND_MESSAGE; import static digit.config.ServiceConstants.INVALID_PLAN_CONFIG_ID_CODE; import static digit.config.ServiceConstants.INVALID_PLAN_CONFIG_ID_MESSAGE; import static digit.config.ServiceConstants.JSONPATH_ERROR_CODE; import static digit.config.ServiceConstants.JSONPATH_ERROR_MESSAGE; +import static digit.config.ServiceConstants.LOCALITY_CODE; +import static digit.config.ServiceConstants.LOCALITY_NOT_PRESENT_IN_MAPPED_TO_CODE; +import static digit.config.ServiceConstants.LOCALITY_NOT_PRESENT_IN_MAPPED_TO_MESSAGE; +import static digit.config.ServiceConstants.MAPPED_TO_VALIDATION_ERROR_CODE; import static digit.config.ServiceConstants.MDMS_MASTER_ASSUMPTION; +import static digit.config.ServiceConstants.MDMS_MASTER_RULE_CONFIGURE_INPUTS; import static digit.config.ServiceConstants.MDMS_MASTER_UPLOAD_CONFIGURATION; import static digit.config.ServiceConstants.MDMS_PLAN_MODULE_NAME; import static digit.config.ServiceConstants.REQUEST_UUID_EMPTY_CODE; @@ -72,6 +80,9 @@ public void validateCreate(PlanConfigurationRequest request) { validateAssumptionValue(planConfiguration); validateFilestoreId(planConfiguration); validateTemplateIdentifierAgainstMDMS(request, mdmsData); + validateOperationsInputAgainstMDMS(request, mdmsData); + validateMappedToForLocality(planConfiguration); + validateTemplateIdentifierAgainstResourceMapping(planConfiguration); } /** @@ -168,6 +179,98 @@ public void validateTemplateIdentifierAgainstMDMS(PlanConfigurationRequest reque } } + /** + * Validates the operations input against the Master Data Management System (MDMS) data. + * + * @param request The PlanConfigurationRequest containing the plan configuration and other details. + * @param mdmsData The MDMS data containing the master rule configure inputs. + */ + public void validateOperationsInputAgainstMDMS(PlanConfigurationRequest request, Object mdmsData) { + PlanConfiguration planConfiguration = request.getPlanConfiguration(); + final String jsonPathForRuleInputs = "$." + MDMS_PLAN_MODULE_NAME + "." + MDMS_MASTER_RULE_CONFIGURE_INPUTS + ".*.*"; + + List ruleInputsListFromMDMS = null; + try { + log.info(jsonPathForRuleInputs); + ruleInputsListFromMDMS = JsonPath.read(mdmsData, jsonPathForRuleInputs); + } catch (Exception e) { + log.error(e.getMessage()); + throw new CustomException(JSONPATH_ERROR_CODE, JSONPATH_ERROR_MESSAGE); + } + + for (Operation operation : planConfiguration.getOperations()) { + if (!ruleInputsListFromMDMS.contains(operation.getInput())) { + log.error("Input Value " + operation.getInput() + " is not present in MDMS Input List"); + throw new CustomException(INPUT_KEY_NOT_FOUND_CODE, INPUT_KEY_NOT_FOUND_MESSAGE); + } + } + } + + /** + * Validates that the 'mappedTo' field in the list of ResourceMappings contains the value "Locality". + * + * @param planConfiguration The plan configuration object to validate + */ + public void validateMappedToForLocality(PlanConfiguration planConfiguration) { + boolean hasLocality = planConfiguration.getResourceMapping().stream() + .anyMatch(mapping -> LOCALITY_CODE.equalsIgnoreCase(mapping.getMappedTo())); + if (!hasLocality) { + throw new CustomException(LOCALITY_NOT_PRESENT_IN_MAPPED_TO_CODE, LOCALITY_NOT_PRESENT_IN_MAPPED_TO_MESSAGE); + } + } + + /** + * Groups the resource mappings by template identifier and validates the 'mappedTo' field + * based on the 'templateIdentifier'. + * + * @param planConfiguration The plan configuration object to validate + */ + public void validateTemplateIdentifierAgainstResourceMapping(PlanConfiguration planConfiguration) { + // Create a map of filestoreId to templateIdentifier + Map filestoreIdToTemplateIdMap = planConfiguration.getFiles().stream() + .collect(Collectors.toMap(File::getFilestoreId, File::getTemplateIdentifier)); + + // Group the resourceMappings by templateIdentifier and validate mappedTo + Map> groupedMappings = planConfiguration.getResourceMapping().stream() + .collect(Collectors.groupingBy(mapping -> filestoreIdToTemplateIdMap.get(mapping.getFilestoreId()))); + + // Validate the 'mappedTo' field based on the 'templateIdentifier' + groupedMappings.forEach((templateId, mappings) -> { + switch (templateId) { + case "Population": + validateMappedTo(mappings, "population"); + break; + case "Facility": + validateMappedTo(mappings, "facility"); + break; + } + }); + + } + + /** + * Validates that all mappings in the list have the expected 'mappedTo' value. + * If none of the mappings match the expected value, a CustomException is thrown. + * + * @param mappings The list of ResourceMappings to validate. + * @param expectedMappedTo The expected value for the 'mappedTo' field. + */ + private void validateMappedTo(List mappings, String expectedMappedTo) { + boolean foundMatch = false; + for (ResourceMapping mapping : mappings) { + if (mapping.getMappedTo().equalsIgnoreCase(expectedMappedTo)) { + foundMatch = true; + break; + } + } + if (!foundMatch) { + throw new CustomException(MAPPED_TO_VALIDATION_ERROR_CODE, + "Atleast one resource's 'mappedTo' must be '" + expectedMappedTo + "'"); + } + } + + + /** * Validates the search request for plan configurations. * @param planConfigurationSearchRequest The search request for plan configurations. diff --git a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java index 2596a456623..f635364ca5b 100644 --- a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java @@ -72,8 +72,10 @@ private ModuleDetail getPlanModuleDetail() { MasterDetail assumptionMasterDetail = MasterDetail.builder().name(MDMS_MASTER_ASSUMPTION).build(); MasterDetail uploadConfigMasterDetail = MasterDetail.builder().name(MDMS_MASTER_UPLOAD_CONFIGURATION).filter(FILTER_ID).build(); + MasterDetail ruleConfigureInputsMasterDetail = MasterDetail.builder().name(MDMS_MASTER_RULE_CONFIGURE_INPUTS).filter(FILTER_DATA).build(); assumptionMasterDetails.add(assumptionMasterDetail); assumptionMasterDetails.add(uploadConfigMasterDetail); + assumptionMasterDetails.add(ruleConfigureInputsMasterDetail); return ModuleDetail.builder().masterDetails(assumptionMasterDetails).moduleName(MDMS_PLAN_MODULE_NAME).build(); } From af176d022f911c83fc46d094b434c744d6045359 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 16 Apr 2024 14:25:55 +0530 Subject: [PATCH 43/53] HLM-5607 adding validations for resource mapping and operation --- .../service/validator/PlanConfigurationValidator.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index 59bdb31a0d2..8f2c8c588e6 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -302,17 +302,13 @@ public void validateUpdateRequest(PlanConfigurationRequest request) { // Validate plan existence validatePlanConfigExistence(request); - //Validate Assumption keys against MDMS data validateAssumptionKeyAgainstMDMS(request, mdmsData); - - //Validate Assumption values under operations with assumption keys validateAssumptionValue(planConfiguration); - - //Validate Resource Mapping's Filestore Ids validateFilestoreId(planConfiguration); - - //validate Template Identifier against MDMS data validateTemplateIdentifierAgainstMDMS(request, mdmsData); + validateOperationsInputAgainstMDMS(request, mdmsData); + validateMappedToForLocality(planConfiguration); + validateTemplateIdentifierAgainstResourceMapping(planConfiguration); } From ca0710e7825925f6b93142846822a906584e3b53 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 16 Apr 2024 16:47:52 +0530 Subject: [PATCH 44/53] HLM-5607 adding new field status in plan configuration --- .../querybuilder/PlanConfigQueryBuilder.java | 8 +++++++- .../repository/rowmapper/PlanConfigRowMapper.java | 1 + .../java/digit/web/models/PlanConfiguration.java | 14 ++++++++++++++ .../models/PlanConfigurationSearchCriteria.java | 3 +++ ...04150000__plan_configuration_add_status_ddl.sql | 2 ++ 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 health-services/plan-service/src/main/resources/db/migration/main/V20241604150000__plan_configuration_add_status_ddl.sql diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java index ded0241a357..6aa7e9da8a5 100644 --- a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java @@ -17,7 +17,7 @@ public PlanConfigQueryBuilder(Configuration config) { this.config = config; } - private static final String PLAN_CONFIG_BASE_SEARCH_QUERY = "SELECT pc.id as plan_configuration_id, pc.tenant_id as plan_configuration_tenant_id, pc.name as plan_configuration_name, pc.execution_plan_id as plan_configuration_execution_plan_id, pc.created_by as plan_configuration_created_by, pc.created_time as plan_configuration_created_time, pc.last_modified_by as plan_configuration_last_modified_by, pc.last_modified_time as plan_configuration_last_modified_time, \n" + + private static final String PLAN_CONFIG_BASE_SEARCH_QUERY = "SELECT pc.id as plan_configuration_id, pc.tenant_id as plan_configuration_tenant_id, pc.name as plan_configuration_name, pc.execution_plan_id as plan_configuration_execution_plan_id, pc.status as plan_configuration_status, pc.created_by as plan_configuration_created_by, pc.created_time as plan_configuration_created_time, pc.last_modified_by as plan_configuration_last_modified_by, pc.last_modified_time as plan_configuration_last_modified_time, \n" + "\t pcf.id as plan_configuration_files_id, pcf.plan_configuration_id as plan_configuration_files_plan_configuration_id, pcf.filestore_id as plan_configuration_files_filestore_id, pcf.input_file_type as plan_configuration_files_input_file_type, pcf.template_identifier as plan_configuration_files_template_identifier, pcf.created_by as plan_configuration_files_created_by, pcf.created_time as plan_configuration_files_created_time, pcf.last_modified_by as plan_configuration_files_last_modified_by, pcf.last_modified_time as plan_configuration_files_last_modified_time,\n" + "\t pca.id as plan_configuration_assumptions_id, pca.key as plan_configuration_assumptions_key, pca.value as plan_configuration_assumptions_value, pca.plan_configuration_id as plan_configuration_assumptions_plan_configuration_id, pca.created_by as plan_configuration_assumptions_created_by, pca.created_time as plan_configuration_assumptions_created_time, pca.last_modified_by as plan_configuration_assumptions_last_modified_by, pca.last_modified_time as plan_configuration_assumptions_last_modified_time,\n" + "\t pco.id as plan_configuration_operations_id, pco.input as plan_configuration_operations_input, pco.operator as plan_configuration_operations_operator, pco.assumption_value as plan_configuration_operations_assumption_value, pco.output as plan_configuration_operations_output, pco.plan_configuration_id as plan_configuration_operations_plan_configuration_id, pco.created_by as plan_configuration_operations_created_by, pco.created_time as plan_configuration_operations_created_time, pco.last_modified_by as plan_configuration_operations_last_modified_by, pco.last_modified_time as plan_configuration_operations_last_modified_time,\n" + @@ -80,6 +80,12 @@ private String buildPlanConfigSearchQuery(PlanConfigurationSearchCriteria criter preparedStmtList.add(criteria.getName()); } + if (criteria.getStatus() != null) { + addClauseIfRequired(preparedStmtList, builder); + builder.append(" pc.status = ?"); + preparedStmtList.add(criteria.getStatus()); + } + if (criteria.getUserUuid() != null) { addClauseIfRequired(preparedStmtList, builder); builder.append(" pc.created_by = ?"); diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java index 825ceebb010..21195fbbfd4 100644 --- a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java @@ -46,6 +46,7 @@ public List extractData(ResultSet rs) throws SQLException, Da planConfigEntry.setTenantId(rs.getString("plan_configuration_tenant_id")); planConfigEntry.setName(rs.getString("plan_configuration_name")); planConfigEntry.setExecutionPlanId(rs.getString("plan_configuration_execution_plan_id")); + planConfigEntry.setStatus(PlanConfiguration.StatusEnum.valueOf(rs.getString("plan_configuration_status").toUpperCase())); planConfigEntry.setAuditDetails(auditDetails); } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java index 6959f0689c2..d741a0cc105 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfiguration.java @@ -1,6 +1,8 @@ package digit.web.models; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import jakarta.validation.constraints.NotEmpty; import java.util.ArrayList; import java.util.List; @@ -46,6 +48,10 @@ public class PlanConfiguration { @Pattern(regexp = "^(?!\\p{Punct}+$).*$", message = "Execution Plan Id must not contain only special characters") private String executionPlanId = null; + @JsonProperty("status") + @NotNull + private StatusEnum status = null; + @JsonProperty("files") @NotNull @NotEmpty @@ -73,4 +79,12 @@ public class PlanConfiguration { @JsonProperty("auditDetails") private @Valid AuditDetails auditDetails; + /** + * The status used in the Plan Configuration + */ + public enum StatusEnum { + DRAFT , + GENERATED + } + } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java index 743e712035b..8f95c24d9fb 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationSearchCriteria.java @@ -31,6 +31,9 @@ public class PlanConfigurationSearchCriteria { @JsonProperty("executionPlanId") private String executionPlanId = null; + @JsonProperty("status") + private String status = null; + @JsonProperty("userUuid") private String userUuid = null; diff --git a/health-services/plan-service/src/main/resources/db/migration/main/V20241604150000__plan_configuration_add_status_ddl.sql b/health-services/plan-service/src/main/resources/db/migration/main/V20241604150000__plan_configuration_add_status_ddl.sql new file mode 100644 index 00000000000..8683e34faef --- /dev/null +++ b/health-services/plan-service/src/main/resources/db/migration/main/V20241604150000__plan_configuration_add_status_ddl.sql @@ -0,0 +1,2 @@ +ALTER TABLE plan_configuration ADD status character varying(64); +UPDATE plan_configuration SET status = 'DRAFT' WHERE status IS NULL; From 7577524f833fa3510af748816bc9640d43b10b96 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 18 Apr 2024 13:50:04 +0530 Subject: [PATCH 45/53] HLM-5692 add totalCount in plan config search query --- .../impl/PlanConfigurationRepositoryImpl.java | 22 ++++++++++++++++++- .../querybuilder/PlanConfigQueryBuilder.java | 15 +++++++++---- .../service/PlanConfigurationService.java | 16 +++++++++++--- .../web/controllers/PlanConfigController.java | 3 +-- .../web/models/PlanConfigurationResponse.java | 3 +++ 5 files changed, 49 insertions(+), 10 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java index 9fdfe0a4f25..125e830ba05 100644 --- a/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanConfigurationRepositoryImpl.java @@ -5,6 +5,7 @@ import digit.repository.PlanConfigurationRepository; import digit.repository.querybuilder.PlanConfigQueryBuilder; import digit.repository.rowmapper.PlanConfigRowMapper; +import digit.util.ResponseInfoFactory; import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; import digit.web.models.PlanConfigurationSearchCriteria; @@ -48,7 +49,7 @@ public void create(PlanConfigurationRequest planConfigurationRequest) { /** * Searches for plan configurations based on the provided search criteria. - * @param planConfigurationSearchCriteria The criteria to use for searching plan configurations. + * @param planConfigurationSearchRequest The criteria to use for searching plan configurations. * @return A list of plan configurations that match the search criteria. */ @Override @@ -60,6 +61,25 @@ public List search(PlanConfigurationSearchCriteria planConfig return jdbcTemplate.query(query, preparedStmtList.toArray(), planConfigRowMapper); } + /** + * Counts the number of plan configurations based on the provided search criteria. + * + * @param planConfigurationSearchCriteria The search criteria for filtering plan configurations. + * @return The total count of plan configurations matching the search criteria. + */ + public Integer count(PlanConfigurationSearchCriteria planConfigurationSearchCriteria) { + List preparedStmtList = new ArrayList<>(); + String query = planConfigQueryBuilder.getPlanConfigCountQuery(planConfigurationSearchCriteria, preparedStmtList); + + log.info("Plan Config count query: " + query); + log.info("preparedStmtList: " + preparedStmtList); + + Integer count = jdbcTemplate.queryForObject(query, preparedStmtList.toArray(), Integer.class); + log.info("Total plan config count is : " + count); + + return count; + } + /** * Pushes an updated existing plan configuration to persister kafka topic. * @param planConfigurationRequest The request containing the updated plan configuration details. diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java index 6aa7e9da8a5..4f73c6bb68e 100644 --- a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanConfigQueryBuilder.java @@ -28,8 +28,9 @@ public PlanConfigQueryBuilder(Configuration config) { "\t LEFT JOIN plan_configuration_operations pco ON pc.id = pco.plan_configuration_id\n" + "\t LEFT JOIN plan_configuration_mapping pcm ON pc.id = pcm.plan_configuration_id"; - private static final String PLAN_CONFIG_SEARCH_QUERY_ORDER_BY_CLAUSE = " ORDER BY pc.last_modified_time DESC "; + private static final String PLAN_CONFIG_SEARCH_QUERY_ORDER_BY_CLAUSE = " ORDER BY pc.last_modified_time DESC"; + private static final String PLAN_CONFIG_SEARCH_QUERY_COUNT_WRAPPER = "SELECT COUNT(DISTINCT pc.id) AS total_count FROM plan_configuration pc "; /** * Constructs a SQL query string for searching PlanConfiguration objects based on the provided search criteria. * Also adds an ORDER BY clause and handles pagination. @@ -39,13 +40,19 @@ public PlanConfigQueryBuilder(Configuration config) { * @return A complete SQL query string for searching PlanConfiguration objects. */ public String getPlanConfigSearchQuery(PlanConfigurationSearchCriteria criteria, List preparedStmtList) { - String query = buildPlanConfigSearchQuery(criteria, preparedStmtList); + String query = buildPlanConfigSearchQuery(criteria, preparedStmtList, Boolean.FALSE); query = QueryUtil.addOrderByClause(query, PLAN_CONFIG_SEARCH_QUERY_ORDER_BY_CLAUSE); query = getPaginatedQuery(query, criteria, preparedStmtList); return query; } + public String getPlanConfigCountQuery(PlanConfigurationSearchCriteria criteria, List preparedStmtList) { + String query = buildPlanConfigSearchQuery(criteria, preparedStmtList, Boolean.TRUE); + query = getPaginatedQuery(query, criteria, preparedStmtList); + return query; + } + /** * Constructs query based on the provided search criteria * @@ -53,8 +60,8 @@ public String getPlanConfigSearchQuery(PlanConfigurationSearchCriteria criteria, * @param preparedStmtList A list to store prepared statement parameters. * @return */ - private String buildPlanConfigSearchQuery(PlanConfigurationSearchCriteria criteria, List preparedStmtList) { - StringBuilder builder = new StringBuilder(PLAN_CONFIG_BASE_SEARCH_QUERY); + private String buildPlanConfigSearchQuery(PlanConfigurationSearchCriteria criteria, List preparedStmtList, Boolean isCount) { + StringBuilder builder = isCount ? new StringBuilder(PLAN_CONFIG_SEARCH_QUERY_COUNT_WRAPPER) : new StringBuilder(PLAN_CONFIG_BASE_SEARCH_QUERY); if (criteria.getTenantId() != null) { addClauseIfRequired(preparedStmtList, builder); diff --git a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java index eb67d0b2738..3f6b9db89f3 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanConfigurationService.java @@ -5,6 +5,7 @@ import digit.repository.impl.PlanConfigurationRepositoryImpl; import digit.service.enrichment.EnrichmentService; import digit.service.validator.PlanConfigurationValidator; +import digit.util.ResponseInfoFactory; import digit.web.models.PlanConfiguration; import digit.web.models.PlanConfigurationRequest; @@ -30,13 +31,16 @@ public class PlanConfigurationService { private PlanConfigurationRepositoryImpl repository; + private ResponseInfoFactory responseInfoFactory; + public PlanConfigurationService(Producer producer, EnrichmentService enrichmentService, Configuration config - , PlanConfigurationValidator validator, PlanConfigurationRepositoryImpl repository) { + , PlanConfigurationValidator validator, PlanConfigurationRepositoryImpl repository, ResponseInfoFactory responseInfoFactory) { this.producer = producer; this.enrichmentService = enrichmentService; this.config = config; this.validator = validator; this.repository = repository; + this.responseInfoFactory = responseInfoFactory; } /** @@ -56,9 +60,15 @@ public PlanConfigurationRequest create(PlanConfigurationRequest request) { * @param request The search request containing the criteria. * @return A list of plan configurations that match the search criteria. */ - public List search(PlanConfigurationSearchRequest request) { + public PlanConfigurationResponse search(PlanConfigurationSearchRequest request) { validator.validateSearchRequest(request); - return repository.search(request.getPlanConfigurationSearchCriteria()); + PlanConfigurationResponse response = PlanConfigurationResponse.builder(). + responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(request.getRequestInfo(), true)) + .planConfiguration(repository.search(request.getPlanConfigurationSearchCriteria())) + .totalCount(repository.count(request.getPlanConfigurationSearchCriteria())) + .build(); + + return response; } /** diff --git a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java index 4db42785b3f..1577ce3dbb1 100644 --- a/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java +++ b/health-services/plan-service/src/main/java/digit/web/controllers/PlanConfigController.java @@ -63,8 +63,7 @@ public ResponseEntity configCreatePost(@Parameter(in */ @RequestMapping(value = "/config/_search", method = RequestMethod.POST) public ResponseEntity configSearchPost(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema()) @Valid @RequestBody PlanConfigurationSearchRequest body) { - List planConfigurationList = planConfigurationService.search(body); - PlanConfigurationResponse response = PlanConfigurationResponse.builder().responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(body.getRequestInfo(), true)).planConfiguration(planConfigurationList).build(); + PlanConfigurationResponse response = planConfigurationService.search(body); return ResponseEntity.status(HttpStatus.OK).body(response); } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java index 2a5277e9e3c..e374ea5ea43 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanConfigurationResponse.java @@ -28,6 +28,9 @@ public class PlanConfigurationResponse { @Valid private List planConfiguration = null; + @JsonProperty("TotalCount") + @Valid + private Integer totalCount = null; public PlanConfigurationResponse addPlanConfigurationResponseItem(PlanConfiguration planConfigurationResponseItem) { if (this.planConfiguration == null) { From 3839c45ebf5b091dae89ba6ba7f8bb1e665a18a4 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 18 Apr 2024 16:58:31 +0530 Subject: [PATCH 46/53] HLM-5711 added validation related changes for metric value --- .../src/main/java/digit/web/models/Assumption.java | 2 +- .../src/main/java/digit/web/models/MetricDetail.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java index 374a3e0fc9e..eaac00d4e09 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Assumption.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Assumption.java @@ -39,7 +39,7 @@ public class Assumption { @Valid @DecimalMin(value = "0.01", inclusive = true, message = "Assumption value must be greater than 0") @DecimalMax(value = "999.99", inclusive = true, message = "Assumption value must be less than 1000") - @Digits(integer = 3, fraction = 2, message = "Value must have up to 3 digits and up to 2 decimal points") + @Digits(integer = 3, fraction = 2, message = "Assumption value must have up to 3 digits and up to 2 decimal points") private BigDecimal value = null; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java b/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java index ffbe649b727..24b5b9b1e65 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java +++ b/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java @@ -1,6 +1,9 @@ package digit.web.models; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.DecimalMax; +import jakarta.validation.constraints.DecimalMin; +import jakarta.validation.constraints.Digits; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; @@ -20,6 +23,9 @@ public class MetricDetail { @JsonProperty("value") @NotNull + @DecimalMin(value = "0.01", inclusive = true, message = "Metric value must be greater than 0") + @DecimalMax(value = "999.99", inclusive = true, message = "Metric value must be less than 1000") + @Digits(integer = 3, fraction = 2, message = "Metric value must have up to 3 digits and up to 2 decimal points") private BigDecimal metricValue = null; @JsonProperty("comparator") From c2c881b9fc6497b459b442e71f1403e5a794f2bb Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 24 Apr 2024 10:28:12 +0530 Subject: [PATCH 47/53] HLM-5740 validation whether plan configuration exists while create plan --- .../main/java/digit/service/PlanValidator.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java index a307f914025..e133a9548ca 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java @@ -1,5 +1,6 @@ package digit.service; +import digit.repository.PlanConfigurationRepository; import digit.repository.PlanRepository; import digit.web.models.*; import org.egov.tracer.model.CustomException; @@ -13,13 +14,19 @@ import java.util.Set; import java.util.stream.Collectors; +import static digit.config.ServiceConstants.INVALID_PLAN_CONFIG_ID_CODE; +import static digit.config.ServiceConstants.INVALID_PLAN_CONFIG_ID_MESSAGE; + @Component public class PlanValidator { private PlanRepository planRepository; - public PlanValidator(PlanRepository planRepository) { + private PlanConfigurationRepository planConfigurationRepository; + + public PlanValidator(PlanRepository planRepository, PlanConfigurationRepository planConfigurationRepository) { this.planRepository = planRepository; + this.planConfigurationRepository = planConfigurationRepository; } /** @@ -149,7 +156,12 @@ private void validateActivities(PlanRequest request) { * @param request */ private void validatePlanConfigurationExistence(PlanRequest request) { - + // If plan id provided is invalid, throw an exception + if(CollectionUtils.isEmpty(planConfigurationRepository.search(PlanConfigurationSearchCriteria.builder() + .id(request.getPlan().getPlanConfigurationId()) + .build()))) { + throw new CustomException(INVALID_PLAN_CONFIG_ID_CODE, INVALID_PLAN_CONFIG_ID_MESSAGE); + } } /** From df2ac4643f6816c0999d9466f796c099b5a83a6c Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Mon, 29 Apr 2024 11:20:37 +0530 Subject: [PATCH 48/53] HLM-5765 making metricComparator an enum --- .../repository/rowmapper/PlanRowMapper.java | 2 +- .../java/digit/web/models/MetricDetail.java | 39 ++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java index cf20654fae3..b3bbe8dc6f4 100644 --- a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java @@ -195,7 +195,7 @@ private void addTargets(ResultSet rs, Plan planEntry, Map target MetricDetail metricDetail = MetricDetail.builder() .metricValue(rs.getBigDecimal("plan_target_metric_value")) - .metricComparator(rs.getString("plan_target_metric_comparator")) + .metricComparator(MetricDetail.MetricComparatorEnum.valueOf(rs.getString("plan_target_metric_comparator"))) .metricUnit(rs.getString("plan_target_metric_unit")) .build(); diff --git a/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java b/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java index 24b5b9b1e65..778af937c1e 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java +++ b/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java @@ -1,6 +1,8 @@ package digit.web.models; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import jakarta.validation.constraints.DecimalMax; import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.Digits; @@ -30,12 +32,45 @@ public class MetricDetail { @JsonProperty("comparator") @NotNull - @Size(min = 1, max = 64) - private String metricComparator = null; + private MetricComparatorEnum metricComparator = null; @JsonProperty("unit") @NotNull @Size(min = 1, max = 128) private String metricUnit = null; + public enum MetricComparatorEnum { + GREATER_THAN(">"), + + LESS_THAN("<"), + + GREATER_THAN_OR_EQUAL_TO(">="), + + LESS_THAN_OR_EQUAL_TO("<="), + + EQUAL("="); + + private final String symbol; + + MetricComparatorEnum(String symbol) { + this.symbol = symbol; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(symbol); + } + + @JsonCreator + public static MetricDetail.MetricComparatorEnum fromValue(String text) { + for (MetricDetail.MetricComparatorEnum b : MetricDetail.MetricComparatorEnum.values()) { + if (String.valueOf(b.symbol).equals(text)) { + return b; + } + } + return null; + } + } + } From 95ed775a8ad73a84cd220e9081de22d0cd04a632 Mon Sep 17 00:00:00 2001 From: siddhant-nawale-egov <162107530+siddhant-nawale-egov@users.noreply.github.com> Date: Thu, 2 May 2024 11:01:05 +0530 Subject: [PATCH 49/53] HLM-5117 changes in operation input validation against mdms data and validateTemplateIdentifierAgainstResourceMapping --- .../java/digit/config/ServiceConstants.java | 5 + .../validator/PlanConfigurationValidator.java | 96 ++++++------------- .../src/main/java/digit/util/MdmsUtil.java | 2 + 3 files changed, 36 insertions(+), 67 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index 53f58c202d0..1188bd9083d 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -92,6 +92,7 @@ public class ServiceConstants { public static final String MDMS_MASTER_ASSUMPTION = "HypothesisAssumptions"; public static final String MDMS_MASTER_UPLOAD_CONFIGURATION = "UploadConfiguration"; public static final String MDMS_MASTER_RULE_CONFIGURE_INPUTS = "RuleConfigureInputs"; + public static final String MDMS_MASTER_SCHEMS = "Schemas"; public static final String MDSM_MASTER_TENANTS = "tenants"; public static final String MDMS_TENANT_MODULE_NAME = "tenant"; @@ -108,4 +109,8 @@ public class ServiceConstants { public static final String LOCALITY_CODE = "Locality"; + public static final String MDMS_SCHEMA_PROPERTIES = "Properties"; + + public static final String MDMS_SCHEMA_PROPERTIES_IS_RULE_CONFIGURE_INPUT = "isRuleConfigureInputs"; + } diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index 8f2c8c588e6..12de01cc15f 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -11,10 +11,8 @@ import digit.web.models.PlanConfigurationSearchCriteria; import digit.web.models.PlanConfigurationSearchRequest; import digit.web.models.ResourceMapping; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; + +import java.util.*; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -22,36 +20,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import static digit.config.ServiceConstants.ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_CODE; -import static digit.config.ServiceConstants.ASSUMPTION_KEY_NOT_FOUND_IN_MDMS_MESSAGE; -import static digit.config.ServiceConstants.ASSUMPTION_VALUE_NOT_FOUND_CODE; -import static digit.config.ServiceConstants.ASSUMPTION_VALUE_NOT_FOUND_MESSAGE; -import static digit.config.ServiceConstants.FILESTORE_ID_INVALID_CODE; -import static digit.config.ServiceConstants.FILESTORE_ID_INVALID_MESSAGE; -import static digit.config.ServiceConstants.INPUT_KEY_NOT_FOUND_CODE; -import static digit.config.ServiceConstants.INPUT_KEY_NOT_FOUND_MESSAGE; -import static digit.config.ServiceConstants.INVALID_PLAN_CONFIG_ID_CODE; -import static digit.config.ServiceConstants.INVALID_PLAN_CONFIG_ID_MESSAGE; -import static digit.config.ServiceConstants.JSONPATH_ERROR_CODE; -import static digit.config.ServiceConstants.JSONPATH_ERROR_MESSAGE; -import static digit.config.ServiceConstants.LOCALITY_CODE; -import static digit.config.ServiceConstants.LOCALITY_NOT_PRESENT_IN_MAPPED_TO_CODE; -import static digit.config.ServiceConstants.LOCALITY_NOT_PRESENT_IN_MAPPED_TO_MESSAGE; -import static digit.config.ServiceConstants.MAPPED_TO_VALIDATION_ERROR_CODE; -import static digit.config.ServiceConstants.MDMS_MASTER_ASSUMPTION; -import static digit.config.ServiceConstants.MDMS_MASTER_RULE_CONFIGURE_INPUTS; -import static digit.config.ServiceConstants.MDMS_MASTER_UPLOAD_CONFIGURATION; -import static digit.config.ServiceConstants.MDMS_PLAN_MODULE_NAME; -import static digit.config.ServiceConstants.REQUEST_UUID_EMPTY_CODE; -import static digit.config.ServiceConstants.REQUEST_UUID_EMPTY_MESSAGE; -import static digit.config.ServiceConstants.SEARCH_CRITERIA_EMPTY_CODE; -import static digit.config.ServiceConstants.SEARCH_CRITERIA_EMPTY_MESSAGE; -import static digit.config.ServiceConstants.TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS_CODE; -import static digit.config.ServiceConstants.TEMPLATE_IDENTIFIER_NOT_FOUND_IN_MDMS_MESSAGE; -import static digit.config.ServiceConstants.TENANT_ID_EMPTY_CODE; -import static digit.config.ServiceConstants.TENANT_ID_EMPTY_MESSAGE; -import static digit.config.ServiceConstants.USER_UUID_MISMATCH_CODE; -import static digit.config.ServiceConstants.USER_UUID_MISMATCH_MESSAGE; +import static digit.config.ServiceConstants.*; @Component @Slf4j @@ -82,7 +51,6 @@ public void validateCreate(PlanConfigurationRequest request) { validateTemplateIdentifierAgainstMDMS(request, mdmsData); validateOperationsInputAgainstMDMS(request, mdmsData); validateMappedToForLocality(planConfiguration); - validateTemplateIdentifierAgainstResourceMapping(planConfiguration); } /** @@ -187,8 +155,7 @@ public void validateTemplateIdentifierAgainstMDMS(PlanConfigurationRequest reque */ public void validateOperationsInputAgainstMDMS(PlanConfigurationRequest request, Object mdmsData) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); - final String jsonPathForRuleInputs = "$." + MDMS_PLAN_MODULE_NAME + "." + MDMS_MASTER_RULE_CONFIGURE_INPUTS + ".*.*"; - + final String jsonPathForRuleInputs = "$." + MDMS_PLAN_MODULE_NAME + "." + MDMS_MASTER_SCHEMS; List ruleInputsListFromMDMS = null; try { log.info(jsonPathForRuleInputs); @@ -197,15 +164,38 @@ public void validateOperationsInputAgainstMDMS(PlanConfigurationRequest request, log.error(e.getMessage()); throw new CustomException(JSONPATH_ERROR_CODE, JSONPATH_ERROR_MESSAGE); } - + List allowedColumns = getRuleConfigInputsFromSchema(ruleInputsListFromMDMS); + planConfiguration.getOperations().stream() + .map(Operation::getOutput) + .forEach(allowedColumns::add); for (Operation operation : planConfiguration.getOperations()) { - if (!ruleInputsListFromMDMS.contains(operation.getInput())) { + if (!allowedColumns.contains(operation.getInput())) { log.error("Input Value " + operation.getInput() + " is not present in MDMS Input List"); throw new CustomException(INPUT_KEY_NOT_FOUND_CODE, INPUT_KEY_NOT_FOUND_MESSAGE); } } } + // helper function + public static List getRuleConfigInputsFromSchema(List schemas) { + if (schemas == null) { + return new ArrayList<>(); + } + Set finalData = new HashSet<>(); + for (Object item : schemas) { + LinkedHashMap columns = (LinkedHashMap) ((LinkedHashMap) item).get(MDMS_SCHEMA_PROPERTIES); + for(Map.Entry column : columns.entrySet()){ + LinkedHashMap data = column.getValue(); + if(data.get(MDMS_SCHEMA_PROPERTIES_IS_RULE_CONFIGURE_INPUT)){ + finalData.add(column.getKey()); + } + } + } + return new ArrayList<>(finalData); + } + + + /** * Validates that the 'mappedTo' field in the list of ResourceMappings contains the value "Locality". * @@ -219,34 +209,7 @@ public void validateMappedToForLocality(PlanConfiguration planConfiguration) { } } - /** - * Groups the resource mappings by template identifier and validates the 'mappedTo' field - * based on the 'templateIdentifier'. - * - * @param planConfiguration The plan configuration object to validate - */ - public void validateTemplateIdentifierAgainstResourceMapping(PlanConfiguration planConfiguration) { - // Create a map of filestoreId to templateIdentifier - Map filestoreIdToTemplateIdMap = planConfiguration.getFiles().stream() - .collect(Collectors.toMap(File::getFilestoreId, File::getTemplateIdentifier)); - - // Group the resourceMappings by templateIdentifier and validate mappedTo - Map> groupedMappings = planConfiguration.getResourceMapping().stream() - .collect(Collectors.groupingBy(mapping -> filestoreIdToTemplateIdMap.get(mapping.getFilestoreId()))); - - // Validate the 'mappedTo' field based on the 'templateIdentifier' - groupedMappings.forEach((templateId, mappings) -> { - switch (templateId) { - case "Population": - validateMappedTo(mappings, "population"); - break; - case "Facility": - validateMappedTo(mappings, "facility"); - break; - } - }); - } /** * Validates that all mappings in the list have the expected 'mappedTo' value. @@ -308,7 +271,6 @@ public void validateUpdateRequest(PlanConfigurationRequest request) { validateTemplateIdentifierAgainstMDMS(request, mdmsData); validateOperationsInputAgainstMDMS(request, mdmsData); validateMappedToForLocality(planConfiguration); - validateTemplateIdentifierAgainstResourceMapping(planConfiguration); } diff --git a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java index f635364ca5b..d8b190302ae 100644 --- a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java @@ -73,9 +73,11 @@ private ModuleDetail getPlanModuleDetail() { MasterDetail assumptionMasterDetail = MasterDetail.builder().name(MDMS_MASTER_ASSUMPTION).build(); MasterDetail uploadConfigMasterDetail = MasterDetail.builder().name(MDMS_MASTER_UPLOAD_CONFIGURATION).filter(FILTER_ID).build(); MasterDetail ruleConfigureInputsMasterDetail = MasterDetail.builder().name(MDMS_MASTER_RULE_CONFIGURE_INPUTS).filter(FILTER_DATA).build(); + MasterDetail SchemaDetails = MasterDetail.builder().name("Schemas").filter("$.*.schema").build(); assumptionMasterDetails.add(assumptionMasterDetail); assumptionMasterDetails.add(uploadConfigMasterDetail); assumptionMasterDetails.add(ruleConfigureInputsMasterDetail); + assumptionMasterDetails.add(SchemaDetails); return ModuleDetail.builder().masterDetails(assumptionMasterDetails).moduleName(MDMS_PLAN_MODULE_NAME).build(); } From 8289220e6c143b1da4b545b2a91f7fb51c104a4b Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 2 May 2024 12:38:10 +0530 Subject: [PATCH 50/53] HLM-5117 changing localhost --- .../plan-service/src/main/resources/application.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/health-services/plan-service/src/main/resources/application.properties b/health-services/plan-service/src/main/resources/application.properties index 9695b36c299..7a8b4258ed8 100644 --- a/health-services/plan-service/src/main/resources/application.properties +++ b/health-services/plan-service/src/main/resources/application.properties @@ -7,12 +7,12 @@ app.timezone=UTC #DATABASE CONFIGURATION spring.datasource.driver-class-name=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://localhost:5433/plandb +spring.datasource.url=jdbc:postgresql://localhost:5432/plandb spring.datasource.username=postgres spring.datasource.password=postgres #FLYWAY CONFIGURATION -spring.flyway.url=jdbc:postgresql://localhost:5433/plandb +spring.flyway.url=jdbc:postgresql://localhost:5432/plandb spring.flyway.user=postgres spring.flyway.password=postgres spring.flyway.table=public From c64b14fa6312ce737f4f4c9145f86aae64c361ad Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 2 May 2024 13:18:50 +0530 Subject: [PATCH 51/53] HLM-5765 making changes to planrowmapper --- .../main/java/digit/repository/rowmapper/PlanRowMapper.java | 2 +- .../src/main/java/digit/web/models/MetricDetail.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java index b3bbe8dc6f4..39403beb936 100644 --- a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java @@ -195,7 +195,7 @@ private void addTargets(ResultSet rs, Plan planEntry, Map target MetricDetail metricDetail = MetricDetail.builder() .metricValue(rs.getBigDecimal("plan_target_metric_value")) - .metricComparator(MetricDetail.MetricComparatorEnum.valueOf(rs.getString("plan_target_metric_comparator"))) + .metricComparator(MetricDetail.MetricComparatorEnum.fromValue(rs.getString("plan_target_metric_comparator"))) .metricUnit(rs.getString("plan_target_metric_unit")) .build(); diff --git a/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java b/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java index 778af937c1e..40452bb02d1 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java +++ b/health-services/plan-service/src/main/java/digit/web/models/MetricDetail.java @@ -63,8 +63,8 @@ public String toString() { } @JsonCreator - public static MetricDetail.MetricComparatorEnum fromValue(String text) { - for (MetricDetail.MetricComparatorEnum b : MetricDetail.MetricComparatorEnum.values()) { + public static MetricComparatorEnum fromValue(String text) { + for (MetricComparatorEnum b : MetricComparatorEnum.values()) { if (String.valueOf(b.symbol).equals(text)) { return b; } From 6b9a2ab236b5d0625766f0f94049aca4f3834095 Mon Sep 17 00:00:00 2001 From: siddhant-nawale-egov <162107530+siddhant-nawale-egov@users.noreply.github.com> Date: Thu, 2 May 2024 15:56:24 +0530 Subject: [PATCH 52/53] HLM-5117 changes in operation input validation with section and filetype checks --- .../java/digit/config/ServiceConstants.java | 6 ++++++ .../validator/PlanConfigurationValidator.java | 18 +++++++++++++++--- .../src/main/java/digit/util/MdmsUtil.java | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index 1188bd9083d..4816aa22e14 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -109,6 +109,12 @@ public class ServiceConstants { public static final String LOCALITY_CODE = "Locality"; + public static final String MDMS_SCHEMA_SECTION = "section"; + + public static final String MDMS_SCHEMA_TYPE = "type"; + + public static final String MDMS_SCHEMA_SCHEMA = "schema"; + public static final String MDMS_SCHEMA_PROPERTIES = "Properties"; public static final String MDMS_SCHEMA_PROPERTIES_IS_RULE_CONFIGURE_INPUT = "isRuleConfigureInputs"; diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java index 12de01cc15f..fcf8421d536 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanConfigurationValidator.java @@ -155,6 +155,15 @@ public void validateTemplateIdentifierAgainstMDMS(PlanConfigurationRequest reque */ public void validateOperationsInputAgainstMDMS(PlanConfigurationRequest request, Object mdmsData) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); + List files = planConfiguration.getFiles(); + List templateIds = files.stream() + .map(File::getTemplateIdentifier) + .collect(Collectors.toList()); + List inputFileTypes = files.stream() + .map(File::getInputFileType) + .map(File.InputFileTypeEnum::toString) + .collect(Collectors.toList()); + final String jsonPathForRuleInputs = "$." + MDMS_PLAN_MODULE_NAME + "." + MDMS_MASTER_SCHEMS; List ruleInputsListFromMDMS = null; try { @@ -164,7 +173,7 @@ public void validateOperationsInputAgainstMDMS(PlanConfigurationRequest request, log.error(e.getMessage()); throw new CustomException(JSONPATH_ERROR_CODE, JSONPATH_ERROR_MESSAGE); } - List allowedColumns = getRuleConfigInputsFromSchema(ruleInputsListFromMDMS); + List allowedColumns = getRuleConfigInputsFromSchema(ruleInputsListFromMDMS, templateIds, inputFileTypes); planConfiguration.getOperations().stream() .map(Operation::getOutput) .forEach(allowedColumns::add); @@ -177,13 +186,16 @@ public void validateOperationsInputAgainstMDMS(PlanConfigurationRequest request, } // helper function - public static List getRuleConfigInputsFromSchema(List schemas) { + public static List getRuleConfigInputsFromSchema(List schemas, List templateIds, List inputFileTypes) { if (schemas == null) { return new ArrayList<>(); } Set finalData = new HashSet<>(); for (Object item : schemas) { - LinkedHashMap columns = (LinkedHashMap) ((LinkedHashMap) item).get(MDMS_SCHEMA_PROPERTIES); + LinkedHashMap schemaEntity = (LinkedHashMap) item; + if(!templateIds.contains(schemaEntity.get(MDMS_SCHEMA_SECTION)) || !inputFileTypes.contains(schemaEntity.get(MDMS_SCHEMA_TYPE))) continue; + LinkedHashMap columns = (LinkedHashMap)((LinkedHashMap) schemaEntity.get(MDMS_SCHEMA_SCHEMA)).get(MDMS_SCHEMA_PROPERTIES); + if(columns == null) return new ArrayList<>(); for(Map.Entry column : columns.entrySet()){ LinkedHashMap data = column.getValue(); if(data.get(MDMS_SCHEMA_PROPERTIES_IS_RULE_CONFIGURE_INPUT)){ diff --git a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java index d8b190302ae..c670233f58d 100644 --- a/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/MdmsUtil.java @@ -73,7 +73,7 @@ private ModuleDetail getPlanModuleDetail() { MasterDetail assumptionMasterDetail = MasterDetail.builder().name(MDMS_MASTER_ASSUMPTION).build(); MasterDetail uploadConfigMasterDetail = MasterDetail.builder().name(MDMS_MASTER_UPLOAD_CONFIGURATION).filter(FILTER_ID).build(); MasterDetail ruleConfigureInputsMasterDetail = MasterDetail.builder().name(MDMS_MASTER_RULE_CONFIGURE_INPUTS).filter(FILTER_DATA).build(); - MasterDetail SchemaDetails = MasterDetail.builder().name("Schemas").filter("$.*.schema").build(); + MasterDetail SchemaDetails = MasterDetail.builder().name("Schemas").build(); assumptionMasterDetails.add(assumptionMasterDetail); assumptionMasterDetails.add(uploadConfigMasterDetail); assumptionMasterDetails.add(ruleConfigureInputsMasterDetail); From 49b0f3f26071e6f2f2ade70387119c10a5564e98 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 14 May 2024 11:31:59 +0530 Subject: [PATCH 53/53] HLM-5180 making activities and resources empty instead of null in search response --- .../digit/repository/rowmapper/PlanRowMapper.java | 11 +++++++++++ .../src/main/java/digit/web/models/Plan.java | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java index 39403beb936..a82919fed46 100644 --- a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java @@ -80,6 +80,11 @@ private void addActivities(ResultSet rs, Plan plan, addActivityConditions(rs, activityMap.get(activityId), conditionMap); return; } + else if (ObjectUtils.isEmpty(activityId)) { + // Set activities list to empty if no activity found + plan.setActivities(new ArrayList<>()); + return; + } String dependencies = rs.getString("plan_activity_dependencies"); AuditDetails auditDetails = AuditDetails.builder() @@ -116,6 +121,8 @@ private void addActivityConditions(ResultSet rs, Activity activity, Map conditionList = new ArrayList<>(); + activity.setConditions(conditionList); return; } @@ -150,6 +157,8 @@ private void addResources(ResultSet rs, Plan planEntry, Map re String resourceId = rs.getString("plan_resource_id"); if(ObjectUtils.isEmpty(resourceId) || resourceMap.containsKey(resourceId)) { + List resourceList = new ArrayList<>(); + planEntry.setResources(resourceList); return; } @@ -183,6 +192,8 @@ private void addTargets(ResultSet rs, Plan planEntry, Map target String targetId = rs.getString("plan_target_id"); if(ObjectUtils.isEmpty(targetId) || targetMap.containsKey(targetId)) { + List targetList = new ArrayList<>(); + planEntry.setTargets(targetList); return; } diff --git a/health-services/plan-service/src/main/java/digit/web/models/Plan.java b/health-services/plan-service/src/main/java/digit/web/models/Plan.java index 6001d223ef6..f1fb59a400e 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Plan.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Plan.java @@ -48,15 +48,15 @@ public class Plan { @JsonProperty("activities") @Valid - private List activities = null; + private List activities; @JsonProperty("resources") @Valid - private List resources = null; + private List resources; @JsonProperty("targets") @Valid - private List targets = null; + private List targets; @JsonProperty("auditDetails") private AuditDetails auditDetails = null;