diff --git a/Makefile b/Makefile
index ff544ce15..92c1064a7 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,8 @@ RELEASE_VERSION = v0.0.14
IMAGES := ghcr.io/sunbird-rc/sunbird-rc-core ghcr.io/sunbird-rc/sunbird-rc-nginx ghcr.io/sunbird-rc/sunbird-rc-context-proxy-service \
ghcr.io/sunbird-rc/sunbird-rc-public-key-service ghcr.io/sunbird-rc/sunbird-rc-keycloak ghcr.io/sunbird-rc/sunbird-rc-certificate-api \
ghcr.io/sunbird-rc/sunbird-rc-certificate-signer ghcr.io/sunbird-rc/sunbird-rc-notification-service ghcr.io/sunbird-rc/sunbird-rc-claim-ms \
- ghcr.io/sunbird-rc/sunbird-rc-digilocker-certificate-api ghcr.io/sunbird-rc/sunbird-rc-bulk-issuance ghcr.io/sunbird-rc/sunbird-rc-metrics
+ ghcr.io/sunbird-rc/sunbird-rc-digilocker-certificate-api ghcr.io/sunbird-rc/sunbird-rc-bulk-issuance ghcr.io/sunbird-rc/sunbird-rc-metrics \
+ ghcr.io/sunbird-rc/id-gen-service
build: java/registry/target/registry.jar
echo ${SOURCES}
rm -rf java/claim/target/*.jar
@@ -20,6 +21,7 @@ build: java/registry/target/registry.jar
make -C services/metrics docker
make -C services/digilocker-certificate-api docker
make -C services/bulk_issuance docker
+ make -C services/id-gen-service docker
docker build -t ghcr.io/sunbird-rc/sunbird-rc-nginx .
java/registry/target/registry.jar: $(SOURCES)
diff --git a/docker-compose.yml b/docker-compose.yml
index 02766fcd8..c6ea9150d 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -352,3 +352,16 @@ services:
test:
wget --no-verbose --tries=1 --spider http://localhost:8123/ping || exit
1
+ id-gen-service:
+ image: ghcr.io/sunbird-rc/id-gen-service
+ ports:
+ - '8014:8014'
+ environment:
+ server.port: 8014
+ server.servlet.context-path: /
+ spring.datasource.url: jdbc:postgresql://db:5432/registry
+ spring.flyway.baseline-on-migrate: "true"
+ egov.mdms.provider: org.egov.id.masterdata.provider.DBMasterDataProvider
+ depends_on:
+ db:
+ condition: service_healthy
diff --git a/services/id-gen-service/.gitignore b/services/id-gen-service/.gitignore
new file mode 100644
index 000000000..2af7cefb0
--- /dev/null
+++ b/services/id-gen-service/.gitignore
@@ -0,0 +1,24 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+nbproject/private/
+build/
+nbbuild/
+dist/
+nbdist/
+.nb-gradle/
\ No newline at end of file
diff --git a/services/id-gen-service/CHANGELOG.md b/services/id-gen-service/CHANGELOG.md
new file mode 100644
index 000000000..d99922b2d
--- /dev/null
+++ b/services/id-gen-service/CHANGELOG.md
@@ -0,0 +1,37 @@
+All notable changes to this module will be documented in this file.
+
+## 1.2.4 - 2023-02-06
+- Transition from 1.2.4-beta version to 1.2.4 version
+
+## 1.2.4-beta - 2022-09-20
+- Upgraded spring-boot-starter-parent to 2.2.13 and spring beans to 5.2.20.RELEASE. Remove log4j depencdency which was not used
+
+## 1.2.3 - 2022-01-13
+- Updated to log4j2 version 2.17.1
+
+## 1.2.2 - 2021-05-11
+
+- TimeZone is now made configurable
+
+## 1.2.1 - 2021-02-26
+
+- Updated domain name in application.properties
+- Added size validations
+- Change the time zone to IST for date generation
+
+## 1.2.0 - 2020-06-17
+
+- Added typescript definition generation plugin
+- Upgraded to tracer:`2.0.0-SNAPSHOT`
+- Upgraded to spring boot `2.2.6-RELEASE`
+- Upgraded to flyway-core `6.4.3 version`
+
+## 1.1.0
+
+- Added option to auto create sequences
+- Moved id generation config from DB to MDMS
+- Set `autocreate.new.seq` to `true` to enable auto creation of sequences
+
+## 1.0.0
+
+- Base version
\ No newline at end of file
diff --git a/services/id-gen-service/Dockerfile b/services/id-gen-service/Dockerfile
new file mode 100644
index 000000000..4f760a03b
--- /dev/null
+++ b/services/id-gen-service/Dockerfile
@@ -0,0 +1,4 @@
+FROM frolvlad/alpine-java:jdk8-slim
+WORKDIR /app
+ADD ./target/egov-idgen-1.2.4-SNAPSHOT.jar id-gen-service.jar
+ENTRYPOINT ["java", "-jar", "id-gen-service.jar"]
diff --git a/services/id-gen-service/LOCALSETUP.md b/services/id-gen-service/LOCALSETUP.md
new file mode 100644
index 000000000..ee8515aa0
--- /dev/null
+++ b/services/id-gen-service/LOCALSETUP.md
@@ -0,0 +1,36 @@
+# Local Setup
+
+This document will walk you through the dependencies of this service and how to set it up locally
+
+- To setup the egov-idgen service in your local system, clone the [Core Service repository](https://github.com/egovernments/core-services).
+
+## Dependencies
+
+### Infra Dependency
+
+- [X] Postgres DB
+- [ ] Redis
+- [ ] Elasticsearch
+- [ ] Kafka
+ - [ ] Consumer
+ - [ ] Producer
+
+## Running Locally
+
+To run the IdGen services in your local system, you need to port forward below services
+
+```bash
+function kgpt(){kubectl get pods -n egov --selector=app=$1 --no-headers=true | head -n1 | awk '{print $1}'}
+kubectl port-forward -n egov $(kgpt egov-mdms-service) 8088:8080
+```
+
+To run the notification mail services locally, update below listed properties in `application.properties` before running the project:
+
+```ini
+# The host of the running environment (eg:https://egov-micro-qa.egovernments.org/citizen)
+mdms.service.host=http://127.0.0.1:8088/
+
+# MDMS service URI. i.e egov-mdms-service/v1/_search
+mdms.service.search.uri=
+```
+
diff --git a/services/id-gen-service/Makefile b/services/id-gen-service/Makefile
new file mode 100644
index 000000000..01ebfc1a8
--- /dev/null
+++ b/services/id-gen-service/Makefile
@@ -0,0 +1,11 @@
+IMAGE_NAME=ghcr.io/sunbird-rc/id-gen-service
+
+build:
+ rm -rf ./target
+ mvn clean install
+
+docker: build
+ docker build -t $(IMAGE_NAME) .
+
+release: docker
+ @docker push $(IMAGE_NAME):latest
\ No newline at end of file
diff --git a/services/id-gen-service/README.md b/services/id-gen-service/README.md
new file mode 100644
index 000000000..86bbcf2c8
--- /dev/null
+++ b/services/id-gen-service/README.md
@@ -0,0 +1,41 @@
+# egov-idgen service
+
+The egov-idgen service generates new id based on the id formats passed. The application exposes a Rest API to take in requests and provide the ids in response in the requested format.
+
+### DB UML Diagram
+
+- TBD
+
+### Service Dependencies
+
+- egov-mdms-service
+
+### Swagger API Contract
+
+Link to the swagger API contract yaml and editor link like below
+
+http://editor.swagger.io/?url=https://raw.githubusercontent.com/egovernments/egov-services/master/docs/idgen/contracts/v1-0-0.yml#!/
+
+
+## Service Details
+
+The application can be run as any other spring boot application but needs lombok extension added in your ide to load it. Once the application is up and running API requests can be posted to the url and ids can be generated.
+In case of intellij the plugin can be installed directly, for eclipse the lombok jar location has to be added in eclipse.ini file in this format -javaagent:lombok.jar.
+
+
+### API Details
+
+- id/v1/_genearte
+
+## Reference document
+
+Details on every parameters and its significance are mentioned in the document - `https://digit-discuss.atlassian.net/l/c/eH501QE3`
+
+
+### Kafka Consumers
+
+- NA
+
+### Kafka Producers
+
+- NA
\ No newline at end of file
diff --git a/services/id-gen-service/pom.xml b/services/id-gen-service/pom.xml
new file mode 100644
index 000000000..66ca91368
--- /dev/null
+++ b/services/id-gen-service/pom.xml
@@ -0,0 +1,148 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.2.13.RELEASE
+
+
+ org.egov
+ egov-idgen
+ 1.2.4-SNAPSHOT
+ egov-idgen
+ Id generation service
+
+ 2.17.1
+ UTF-8
+ 1.8
+ UTF-8
+ 1.18.8
+
+
+
+ org.springframework
+ spring-beans
+ 5.2.20.RELEASE
+
+
+ org.projectlombok
+ lombok
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.postgresql
+ postgresql
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+ org.aspectj
+ aspectjrt
+
+
+ org.springframework
+ spring-aspects
+
+
+ org.flywaydb
+ flyway-core
+ 6.4.3
+
+
+ org.egov.services
+ tracer
+ 2.0.0-SNAPSHOT
+
+
+ org.egov
+ mdms-client
+ 0.0.3-SNAPSHOT
+
+
+ com.jayway.jsonpath
+ json-path
+ 2.2.0
+
+
+
+
+ repo.egovernments.org
+ eGov ERP Releases Repository
+ https://nexus-repo.egovernments.org/nexus/content/repositories/releases/
+
+
+ repo.egovernments.org.snapshots
+ eGov ERP Snapshots Repository
+ https://nexus-repo.egovernments.org/nexus/content/repositories/snapshots/
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.projectlombok
+ lombok
+
+
+ org.springframework.boot
+ spring-boot-devtools
+
+
+
+
+
+ cz.habarta.typescript-generator
+ typescript-generator-maven-plugin
+ 2.22.595
+
+
+ generate
+
+ generate
+
+ process-classes
+
+
+
+ jackson2
+
+ org.egov.id.model.IdRequest
+ org.egov.id.model.IdResponse
+
+
+ org.egov.id.model.ResponseStatusEnum$ResponseStatusEnum:ResponseStatus
+
+
+ org.egov.id.model.Error:Error
+ org.egov.id.model.ErrorRes:ErrorRes
+ org.egov.id.model.Role:Role
+ org.egov.id.model.UserInfo:UserInfo
+
+ Digit
+ true
+ module
+
+
+
+
+
diff --git a/services/id-gen-service/src/main/java/org/egov/PtIdGenerationApplication.java b/services/id-gen-service/src/main/java/org/egov/PtIdGenerationApplication.java
new file mode 100644
index 000000000..1673ac998
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/PtIdGenerationApplication.java
@@ -0,0 +1,50 @@
+package org.egov;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.egov.id.masterdata.MasterDataProvider;
+import org.egov.id.utils.Constants;
+import org.egov.tracer.config.TracerConfiguration;
+import org.egov.tracer.model.CustomException;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Import;
+import org.springframework.util.ObjectUtils;
+
+/**
+ * Description : This is initialization class for pt-idGeneration module
+ *
+ * @author Pavan Kumar Kamma
+ *
+ */
+@SpringBootApplication
+@Slf4j
+@Import({TracerConfiguration.class})
+public class PtIdGenerationApplication {
+
+ @Value("${egov.mdms.provider}")
+ private String masterDataProviderClassName;
+ public static void main(String[] args) {
+ SpringApplication.run(PtIdGenerationApplication.class, args);
+ }
+
+ @Bean
+ public MasterDataProvider masterDataProvider() {
+ MasterDataProvider masterDataProvider = null;
+ try{
+ if(ObjectUtils.isEmpty(masterDataProviderClassName)){
+ masterDataProviderClassName = Constants.DEFAULT_MASTER_DATA_PROVIDER;
+ }
+ Class> masterDataProviderClass = Class.forName(masterDataProviderClassName);
+
+ masterDataProvider = (MasterDataProvider) masterDataProviderClass.newInstance();
+ log.info("Invoked MasterDataProvider with Classname: {}", masterDataProviderClassName);
+ } catch(ClassNotFoundException | InstantiationException | IllegalAccessException e){
+ log.error("MDMS provider class {} cannot be instantiate with exception: {}", masterDataProviderClassName, ExceptionUtils.getStackTrace(e));
+ throw new CustomException("Unable to load MDMS provider class", "MDMS Provider Init Exception");
+ }
+ return masterDataProvider;
+ }
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/api/IdGenerationController.java b/services/id-gen-service/src/main/java/org/egov/id/api/IdGenerationController.java
new file mode 100644
index 000000000..171ababf6
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/api/IdGenerationController.java
@@ -0,0 +1,44 @@
+package org.egov.id.api;
+
+import org.egov.id.model.IdGenerationRequest;
+import org.egov.id.model.IdGenerationResponse;
+import org.egov.id.service.IdGenerationService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+
+/**
+ * api's related to the IdGeneration Controller
+ *
+ * @author Pavan Kumar Kamma
+ */
+@RestController
+@RequestMapping(path = "/id/")
+public class IdGenerationController {
+
+ @Autowired
+ IdGenerationService idGenerationService;
+
+ /**
+ * description: generate unique ID for property
+ *
+ * @param IdGenerationRequest
+ * @return IdGenerationResponse
+ * @throws Exception
+ */
+ @RequestMapping(method = RequestMethod.POST, path = "_generate")
+ public IdGenerationResponse generateIdResponse(
+ @RequestBody @Valid IdGenerationRequest idGenerationRequest)
+ throws Exception {
+
+ IdGenerationResponse idGenerationResponse = idGenerationService
+ .generateIdResponse(idGenerationRequest);
+
+ return idGenerationResponse;
+ }
+
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/config/PropertiesManager.java b/services/id-gen-service/src/main/java/org/egov/id/config/PropertiesManager.java
new file mode 100644
index 000000000..492aa3a1b
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/config/PropertiesManager.java
@@ -0,0 +1,99 @@
+package org.egov.id.config;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+/**
+ *
+ * @author Yosadhara
+ *
+ */
+@Configuration
+@ToString
+@NoArgsConstructor
+@SuppressWarnings("unused")
+public class PropertiesManager {
+
+ @Autowired
+ Environment environment;
+
+ private String invalidInput;
+
+ private String dbUrl;
+
+ private String dbUserName;
+
+ private String dbPassword;
+
+ private String idGenerationTable;
+
+ private String idSequenceOverflow;
+
+ private String idSequenceNotFound;
+
+ private String invalidIdFormat;
+
+ private String success;
+
+ private String failed;
+
+ private String serverContextpath;
+
+ private String timeZone;
+
+ public String getInvalidInput() {
+ return environment.getProperty("invalid.input");
+ }
+
+ public String getDbUrl() {
+ return environment.getProperty("spring.datasource.url");
+ }
+
+ public String getDbUserName() {
+ return environment.getProperty("spring.datasource.username");
+ }
+
+ public String getDbPassword() {
+ return environment.getProperty("spring.datasource.password");
+ }
+
+ public String getIdGenerationTable() {
+ return environment.getProperty("id.generation.table");
+ }
+
+ public String getIdSequenceOverflow() {
+ return environment.getProperty("id.sequence.overflow");
+ }
+
+ public String getIdSequenceNotFound() {
+ return environment.getProperty("id.sequence.notfound");
+ }
+
+ public String getInvalidIdFormat() {
+ return environment.getProperty("id.invalid.format");
+ }
+
+ public String getSuccess() {
+ return environment.getProperty("success");
+ }
+
+ public String getFailed() {
+ return environment.getProperty("failed");
+ }
+
+ public String getServerContextpath() {
+ return environment.getProperty("server.context-path");
+ }
+
+ public String getCityCodeNotFound() {
+ return environment.getProperty("city.code.notfound");
+ }
+
+ public String getTimeZone(){
+ return environment.getProperty("id.timezone");
+ }
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/exception/GlobalExceptionHandler.java b/services/id-gen-service/src/main/java/org/egov/id/exception/GlobalExceptionHandler.java
new file mode 100644
index 000000000..75323d34a
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/exception/GlobalExceptionHandler.java
@@ -0,0 +1,111 @@
+package org.egov.id.exception;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.egov.id.config.PropertiesManager;
+import org.egov.id.model.Error;
+import org.egov.id.model.ErrorRes;
+import org.egov.id.model.IDSeqNotFoundException;
+import org.egov.id.model.IDSeqOverflowException;
+import org.egov.id.model.InvalidIDFormatException;
+import org.egov.id.model.ResponseInfo;
+import org.egov.id.model.ResponseStatusEnum;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.validation.FieldError;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+import org.springframework.web.context.request.WebRequest;
+
+@RestControllerAdvice
+public class GlobalExceptionHandler {
+
+ @Autowired
+ PropertiesManager propertiesManager;
+
+ /**
+ * Description : MethodArgumentNotValidException type exception handler
+ *
+ * @param ex
+ * @return
+ */
+
+ @ExceptionHandler(MethodArgumentNotValidException.class)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
+ public ErrorRes processValidationError(MethodArgumentNotValidException ex) {
+ Map errors = new HashMap();
+ for (final FieldError error : ex.getBindingResult().getFieldErrors()) {
+ errors.put(error.getField(), error.getDefaultMessage());
+ }
+
+ Error error = new Error(HttpStatus.BAD_REQUEST.toString(), propertiesManager.getInvalidInput(), null, errors);
+ List errorList = new ArrayList();
+ errorList.add(error);
+ ResponseInfo responseInfo = new ResponseInfo();
+ responseInfo.setStatus(ResponseStatusEnum.FAILED);
+ return new ErrorRes(responseInfo, errorList);
+ }
+
+ /**
+ * Description : General exception handler method
+ *
+ * @param ex
+ * @param req
+ * @return
+ */
+ @ExceptionHandler(value = { Exception.class })
+ public ErrorRes unknownException(Exception ex, WebRequest req) {
+ if (ex instanceof InvalidIDFormatException) {
+ Error error = new Error(HttpStatus.BAD_REQUEST.toString(), ((InvalidIDFormatException) ex).getCustomMsg(),
+ null, new HashMap());
+ ResponseInfo responseInfo = new ResponseInfo();
+ responseInfo.setApiId(((InvalidIDFormatException) ex).getRequestInfo().getApiId());
+ responseInfo.setVer(((InvalidIDFormatException) ex).getRequestInfo().getVer());
+ responseInfo.setMsgId(((InvalidIDFormatException) ex).getRequestInfo().getMsgId());
+ responseInfo.setTs(new Date().getTime());
+ responseInfo.setStatus(ResponseStatusEnum.FAILED);
+ List errorList = new ArrayList();
+ errorList.add(error);
+ return new ErrorRes(responseInfo, errorList);
+ } else if (ex instanceof IDSeqOverflowException) {
+ Error error = new Error(HttpStatus.BAD_REQUEST.toString(), ((IDSeqOverflowException) ex).getCustomMsg(),
+ null, new HashMap());
+ ResponseInfo responseInfo = new ResponseInfo();
+ responseInfo.setApiId(((IDSeqOverflowException) ex).getRequestInfo().getApiId());
+ responseInfo.setVer(((IDSeqOverflowException) ex).getRequestInfo().getVer());
+ responseInfo.setMsgId(((IDSeqOverflowException) ex).getRequestInfo().getMsgId());
+ responseInfo.setTs(new Date().getTime());
+ responseInfo.setStatus(ResponseStatusEnum.FAILED);
+ List errorList = new ArrayList();
+ errorList.add(error);
+ return new ErrorRes(responseInfo, errorList);
+ } else if (ex instanceof IDSeqNotFoundException) {
+ Error error = new Error(HttpStatus.BAD_REQUEST.toString(), ((IDSeqNotFoundException) ex).getCustomMsg(),
+ null, new HashMap());
+ ResponseInfo responseInfo = new ResponseInfo();
+ responseInfo.setApiId(((IDSeqNotFoundException) ex).getRequestInfo().getApiId());
+ responseInfo.setVer(((IDSeqNotFoundException) ex).getRequestInfo().getVer());
+ responseInfo.setMsgId(((IDSeqNotFoundException) ex).getRequestInfo().getMsgId());
+ responseInfo.setTs(new Date().getTime());
+ responseInfo.setStatus(ResponseStatusEnum.FAILED);
+ List errorList = new ArrayList();
+ errorList.add(error);
+ return new ErrorRes(responseInfo, errorList);
+ } else {
+ Error error = new Error(HttpStatus.BAD_REQUEST.toString(), ex.getMessage(), null,
+ new HashMap());
+ ResponseInfo responseInfo = new ResponseInfo();
+ responseInfo.setStatus(ResponseStatusEnum.FAILED);
+ List errorList = new ArrayList();
+ errorList.add(error);
+ return new ErrorRes(responseInfo, errorList);
+ }
+ }
+
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/masterdata/MasterDataProvider.java b/services/id-gen-service/src/main/java/org/egov/id/masterdata/MasterDataProvider.java
new file mode 100644
index 000000000..161bcfb2e
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/masterdata/MasterDataProvider.java
@@ -0,0 +1,14 @@
+package org.egov.id.masterdata;
+
+import org.egov.id.model.IdRequest;
+import org.egov.id.model.RequestInfo;
+import org.egov.mdms.model.MasterDetail;
+import org.egov.mdms.model.MdmsResponse;
+
+import java.util.List;
+import java.util.Map;
+
+public interface MasterDataProvider {
+ String getCity(RequestInfo requestInfo, IdRequest idRequest);
+ String getIdFormat(RequestInfo requestInfo, IdRequest idRequest);
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/masterdata/provider/DBMasterDataProvider.java b/services/id-gen-service/src/main/java/org/egov/id/masterdata/provider/DBMasterDataProvider.java
new file mode 100644
index 000000000..0aa686b62
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/masterdata/provider/DBMasterDataProvider.java
@@ -0,0 +1,64 @@
+package org.egov.id.masterdata.provider;
+
+import lombok.extern.slf4j.Slf4j;
+import org.egov.id.masterdata.MasterDataProvider;
+import org.egov.id.model.IdRequest;
+import org.egov.id.model.RequestInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import javax.sql.DataSource;
+
+@Service
+@Slf4j
+public class DBMasterDataProvider implements MasterDataProvider {
+ @Autowired
+ DataSource dataSource;
+
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+
+ @Override
+ public String getCity(RequestInfo requestInfo, IdRequest idRequest) {
+ String city = null;
+ try {
+ String tenantId = idRequest.getTenantId();
+ StringBuffer idSelectQuery = new StringBuffer();
+ idSelectQuery.append("SELECT citycode FROM tenantid_citycode ").append("WHERE tenantid=?");
+ city = jdbcTemplate.queryForObject(idSelectQuery.toString(),new Object[]{tenantId}, String.class);
+ } catch (Exception ex) {
+ log.error("SQL error while trying to retrieve format from DB", ex);
+ }
+ return city;
+ }
+
+ @Override
+ public String getIdFormat(RequestInfo requestInfo, IdRequest idRequest) {
+ String idFormat = null;
+ try {
+ String idName = idRequest.getIdName();
+ String tenantId = idRequest.getTenantId();
+ // select the id format from the id generation table
+ StringBuffer idSelectQuery = new StringBuffer();
+ idSelectQuery.append("SELECT format FROM id_generator ").append(" WHERE idname=? and tenantid=?");
+
+ String rs = jdbcTemplate.queryForObject(idSelectQuery.toString(),new Object[]{idName,tenantId}, String.class);
+ if (!StringUtils.isEmpty(rs)) {
+ idFormat = rs;
+ } else {
+ // querying for the id format with idname
+ StringBuffer idNameQuery = new StringBuffer();
+ idNameQuery.append("SELECT format FROM id_generator ").append(" WHERE idname=?");
+ rs = jdbcTemplate.queryForObject(idSelectQuery.toString(),new Object[]{idName}, String.class);
+ if (!StringUtils.isEmpty(rs))
+ idFormat = rs;
+ }
+ } catch (Exception ex){
+ log.error("SQL error while trying to retrieve format from DB", ex);
+ }
+ return idFormat;
+ }
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/masterdata/provider/WebServiceMasterDataProvider.java b/services/id-gen-service/src/main/java/org/egov/id/masterdata/provider/WebServiceMasterDataProvider.java
new file mode 100644
index 000000000..d2540324f
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/masterdata/provider/WebServiceMasterDataProvider.java
@@ -0,0 +1,180 @@
+package org.egov.id.masterdata.provider;
+
+import java.io.IOException;
+import java.util.*;
+
+import lombok.extern.log4j.Log4j2;
+import org.egov.id.masterdata.MasterDataProvider;
+import org.egov.id.model.IdRequest;
+import org.egov.id.model.RequestInfo;
+import org.egov.mdms.model.MasterDetail;
+import org.egov.mdms.model.MdmsCriteria;
+import org.egov.mdms.model.MdmsCriteriaReq;
+import org.egov.mdms.model.MdmsResponse;
+import org.egov.mdms.model.ModuleDetail;
+import org.egov.mdms.service.MdmsClientService;
+import org.egov.tracer.model.CustomException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.jayway.jsonpath.DocumentContext;
+import com.jayway.jsonpath.JsonPath;
+
+import lombok.extern.log4j.Log4j;
+
+@Service
+@Log4j2
+public class WebServiceMasterDataProvider implements MasterDataProvider {
+
+ @Autowired
+ MdmsClientService mdmsClientService;
+
+ public WebServiceMasterDataProvider() {}
+
+ // 'tenants' & 'citymodule' are the JSON files inside the folder 'tenant'.
+ private static final String tenantMaster = "tenants";
+ private static final String cityMaster = "citymodule";
+ private static final String tenantModule = "tenant";
+
+ //'IdFormat' is the JSON file in the Folder 'common-masters'.
+ private static final String formatMaster = "IdFormat";
+ private static final String formatModule = "common-masters";
+
+ public MdmsResponse getMasterData(RequestInfo requestInfo, String tenantId,
+ Map> masterDetails) {
+
+ MdmsResponse mdmsResponse = null;
+ try {
+ mdmsResponse = mdmsClientService.getMaster(RequestInfo.toCommonRequestInfo(requestInfo), tenantId,
+ masterDetails);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ log.error("Error occurred while fetching MDMS data", e);
+ }
+ return mdmsResponse;
+ }
+
+ /**
+ * Description : This method to get CityCode from Mdms
+ *
+ * @param idRequest
+ * @param requestInfo
+ * @return cityCode
+ * @throws Exception
+ */
+
+ @Override
+ public String getCity(RequestInfo requestInfo, IdRequest idRequest) {
+ Map getCity = doMdmsServiceCall(requestInfo, idRequest);
+ String cityCode = null;
+ try {
+ if (getCity != null) {
+ cityCode = getCity.get(tenantMaster);
+ }
+ if(cityCode== null){
+ throw new CustomException("PARSING ERROR", "City code is Null/not valid");
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ log.error("Error occurred while fetching city code", e);
+ throw new CustomException("PARSING ERROR", "Failed to get citycode from MDMS");
+ }
+ return cityCode;
+ }
+
+ /**
+ * Description : This method to get IdFormat from Mdms
+ *
+ * @param idRequest
+ * @param requestInfo
+ * @return IdFormat
+ * @throws Exception
+ */
+
+ @Override
+ public String getIdFormat(RequestInfo requestInfo, IdRequest idRequest) {
+ Map getIdFormat = doMdmsServiceCall(requestInfo, idRequest);
+ String idFormat = null;
+ try {
+ if (getIdFormat != null) {
+ idFormat = getIdFormat.get(formatMaster);
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ log.error("Error while fetching id format", e);
+ throw new CustomException("PARSING ERROR", "Failed to get formatid from MDMS");
+ }
+ return idFormat;
+ }
+
+ /**
+ * Prepares and returns Mdms search request
+ *
+ * @param requestInfo
+ * @return MAP
+ */
+ private Map doMdmsServiceCall(RequestInfo requestInfo, IdRequest idRequest) {
+
+
+ String idname = idRequest.getIdName();
+ String tenantId = idRequest.getTenantId();
+
+ String idFormatFromMdms = null;
+ String cityCodeFromMdms = null;
+
+
+ Map> masterDetails = new HashMap>();
+
+ List masterDetailListCity = new LinkedList();
+ List masterDetailListFormat = new LinkedList();
+
+ MasterDetail masterDetailForCity = MasterDetail.builder().name(tenantMaster)
+ .filter("[?(@.code=='" + tenantId + "')]").build();
+
+ masterDetailListCity.add(masterDetailForCity);
+
+ MasterDetail masterDetailForFormat = MasterDetail.builder().name(formatMaster)
+ .filter("[?(@.idname=='" + idname + "')]").build();
+
+
+ masterDetailListFormat.add(masterDetailForFormat);
+
+ masterDetails.put(tenantModule, masterDetailListCity);
+ masterDetails.put(formatModule, masterDetailListFormat);
+ MdmsResponse mdmsResponse = null;
+
+ try {
+ mdmsResponse = getMasterData(requestInfo, tenantId, masterDetails);
+
+ if (mdmsResponse.getMdmsRes() != null && mdmsResponse.getMdmsRes().containsKey(tenantModule)
+ && mdmsResponse.getMdmsRes().get(tenantModule).containsKey(tenantMaster)
+ && mdmsResponse.getMdmsRes().get(tenantModule).get(tenantMaster).size() > 0
+ && mdmsResponse.getMdmsRes().get(tenantModule).get(tenantMaster).get(0) != null) {
+ DocumentContext documentContext = JsonPath
+ .parse(mdmsResponse.getMdmsRes().get(tenantModule).get(tenantMaster).get(0));
+
+ cityCodeFromMdms = documentContext.read("$.city.code");
+ log.debug("Found city code as - " + cityCodeFromMdms);
+ }
+ if (mdmsResponse.getMdmsRes() != null && mdmsResponse.getMdmsRes().containsKey(formatModule)
+ && mdmsResponse.getMdmsRes().get(formatModule).containsKey(formatMaster)
+ && mdmsResponse.getMdmsRes().get(formatModule).get(formatMaster).size() > 0
+ && mdmsResponse.getMdmsRes().get(formatModule).get(formatMaster).get(0) != null) {
+ DocumentContext documentContext = JsonPath
+ .parse(mdmsResponse.getMdmsRes().get(formatModule).get(formatMaster).get(0));
+ idFormatFromMdms = documentContext.read("$.format");
+ }
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ log.error("MDMS Fetch failed", e);
+ throw new CustomException("PARSING ERROR", "Failed to get citycode/formatid from MDMS");
+ }
+ Map mdmsCallMap = new HashMap();
+ mdmsCallMap.put(formatMaster, idFormatFromMdms);
+ mdmsCallMap.put(tenantMaster, cityCodeFromMdms);
+
+ return mdmsCallMap;
+ }
+
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/CityCodeNotFoundException.java b/services/id-gen-service/src/main/java/org/egov/id/model/CityCodeNotFoundException.java
new file mode 100644
index 000000000..824b315da
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/CityCodeNotFoundException.java
@@ -0,0 +1,15 @@
+package org.egov.id.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+@AllArgsConstructor
+public class CityCodeNotFoundException extends RuntimeException {
+
+ private String customMsg;
+
+ private RequestInfo requestInfo;
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/Error.java b/services/id-gen-service/src/main/java/org/egov/id/model/Error.java
new file mode 100644
index 000000000..da3242fd4
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/Error.java
@@ -0,0 +1,40 @@
+package org.egov.id.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.validation.constraints.NotNull;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * 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.
+ */
+
+@Setter
+@Getter
+@AllArgsConstructor
+@NoArgsConstructor
+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 Map fileds = new HashMap();
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/ErrorRes.java b/services/id-gen-service/src/main/java/org/egov/id/model/ErrorRes.java
new file mode 100644
index 000000000..00f49404d
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/ErrorRes.java
@@ -0,0 +1,30 @@
+package org.egov.id.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * 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. Author : Narendra
+ */
+
+@Setter
+@Getter
+@AllArgsConstructor
+@NoArgsConstructor
+public class ErrorRes {
+ @JsonProperty("ResponseInfo")
+ private ResponseInfo responseInfo = null;
+
+ @JsonProperty("Errors")
+ private List errors = new ArrayList();
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/IDSeqNotFoundException.java b/services/id-gen-service/src/main/java/org/egov/id/model/IDSeqNotFoundException.java
new file mode 100644
index 000000000..dc8ae4895
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/IDSeqNotFoundException.java
@@ -0,0 +1,26 @@
+package org.egov.id.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * IDSeqNotFoundException
+ *
+ * @author Pavan Kumar kamma
+ *
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class IDSeqNotFoundException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ private String customMsg;
+
+ private RequestInfo requestInfo;
+
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/IDSeqOverflowException.java b/services/id-gen-service/src/main/java/org/egov/id/model/IDSeqOverflowException.java
new file mode 100644
index 000000000..e2aaa4a19
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/IDSeqOverflowException.java
@@ -0,0 +1,25 @@
+package org.egov.id.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * IDSeqOverflowException
+ *
+ * @author Pavan Kumar kamma
+ *
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class IDSeqOverflowException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ private String customMsg;
+
+ private RequestInfo requestInfo;
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/IdGenerationRequest.java b/services/id-gen-service/src/main/java/org/egov/id/model/IdGenerationRequest.java
new file mode 100644
index 000000000..8a68d097d
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/IdGenerationRequest.java
@@ -0,0 +1,34 @@
+package org.egov.id.model;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+
+import javax.validation.Valid;
+
+/**
+ * IdGenerationRequest
+ *
+ * @author Narendra
+ *
+ */
+@Getter
+@Setter
+@ToString
+@AllArgsConstructor
+@NoArgsConstructor
+public class IdGenerationRequest {
+
+ @JsonProperty("RequestInfo")
+ private RequestInfo requestInfo;
+
+ @Valid
+ private List idRequests;
+
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/IdGenerationResponse.java b/services/id-gen-service/src/main/java/org/egov/id/model/IdGenerationResponse.java
new file mode 100644
index 000000000..bfff5d31d
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/IdGenerationResponse.java
@@ -0,0 +1,28 @@
+package org.egov.id.model;
+
+import java.util.List;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+
+/**
+ * IdGenerationResponse
+ *
+ * @author Narendra
+ *
+ */
+@Getter
+@Setter
+@ToString
+@AllArgsConstructor
+@NoArgsConstructor
+public class IdGenerationResponse {
+
+ private ResponseInfo responseInfo;
+
+ private List idResponses;
+
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/IdRequest.java b/services/id-gen-service/src/main/java/org/egov/id/model/IdRequest.java
new file mode 100644
index 000000000..54e740274
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/IdRequest.java
@@ -0,0 +1,41 @@
+package org.egov.id.model;
+
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import lombok.*;
+
+/**
+ * IdRequest
+ *
+ * @author Narendra
+ *
+ */
+@Getter
+@Setter
+@ToString
+@AllArgsConstructor
+@NoArgsConstructor
+public class IdRequest {
+
+ @Size(max = 200)
+ @JsonProperty("idName")
+ @NotNull
+ private String idName;
+
+ @NotNull
+ @Size(max=200)
+ @JsonProperty("tenantId")
+ private String tenantId;
+
+ @Size(max = 200)
+ @JsonProperty("format")
+ private String format;
+
+ @JsonProperty("count")
+ private Integer count;
+
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/IdResponse.java b/services/id-gen-service/src/main/java/org/egov/id/model/IdResponse.java
new file mode 100644
index 000000000..b625f0ec5
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/IdResponse.java
@@ -0,0 +1,24 @@
+package org.egov.id.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+
+/**
+ * IdResponse
+ *
+ * @author Narendra
+ *
+ */
+@Getter
+@Setter
+@ToString
+@AllArgsConstructor
+@NoArgsConstructor
+public class IdResponse {
+
+ private String id;
+
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/InvalidIDFormatException.java b/services/id-gen-service/src/main/java/org/egov/id/model/InvalidIDFormatException.java
new file mode 100644
index 000000000..ed86d369e
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/InvalidIDFormatException.java
@@ -0,0 +1,25 @@
+package org.egov.id.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * InvalidIDFormatException
+ *
+ * @author Pavan Kumar kamma
+ *
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class InvalidIDFormatException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ private String customMsg;
+
+ private RequestInfo requestInfo;
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/RequestInfo.java b/services/id-gen-service/src/main/java/org/egov/id/model/RequestInfo.java
new file mode 100644
index 000000000..efb445c11
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/RequestInfo.java
@@ -0,0 +1,82 @@
+package org.egov.id.model;
+
+import java.io.IOException;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * RequestInfo should be used to carry meta information about the requests to
+ * the server as described in the fields below. All eGov APIs will use
+ * requestinfo as a part of the request body to carry this meta information.
+ * Some of this information will be returned back from the server as part of the
+ * ResponseInfo in the response body to ensure correlation. Author : Narendra
+ */
+
+@Setter
+@Getter
+@AllArgsConstructor
+@NoArgsConstructor
+public class RequestInfo {
+ @JsonProperty("apiId")
+ @NotNull
+ @Size(max = 128)
+ private String apiId = null;
+
+ @JsonProperty("ver")
+ @NotNull
+ @Size(max = 32)
+ private String ver = null;
+
+ @JsonProperty("ts")
+ @NotNull
+ private Long ts = null;
+
+ @JsonProperty("action")
+ @NotNull
+ @Size(max = 32)
+ private String action = null;
+
+ @JsonProperty("did")
+ @Size(max = 1024)
+ private String did = null;
+
+ @JsonProperty("key")
+ @Size(max = 256)
+ private String key = null;
+
+ @JsonProperty("msgId")
+ @NotNull
+ @Size(max = 256)
+ private String msgId = null;
+
+ @JsonProperty("requesterId")
+ @Size(max = 256)
+ private String requesterId = null;
+
+ @JsonProperty("authToken")
+ private String authToken = null;
+
+ @JsonProperty("userInfo")
+ private UserInfo userInfo = null;
+
+ @JsonProperty("correlationId")
+ private String correlationId = null;
+
+ public static org.egov.common.contract.request.RequestInfo toCommonRequestInfo(RequestInfo requestInfo) throws IOException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ String jsonInString = objectMapper.writeValueAsString(requestInfo);
+ org.egov.common.contract.request.RequestInfo requestInfo2 = objectMapper.readValue(jsonInString, org.egov.common.contract.request.RequestInfo.class);
+ return requestInfo2;
+ }
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/ResponseInfo.java b/services/id-gen-service/src/main/java/org/egov/id/model/ResponseInfo.java
new file mode 100644
index 000000000..3334c0326
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/ResponseInfo.java
@@ -0,0 +1,49 @@
+package org.egov.id.model;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * ResponseInfo should be used to carry metadata information about the response
+ * from the server. apiId, ver and msgId in ResponseInfo should always
+ * correspond to the same values in respective request's RequestInfo. Author
+ * : Narendra
+ */
+
+@Setter
+@Getter
+@AllArgsConstructor
+@NoArgsConstructor
+public class ResponseInfo {
+ @JsonProperty("apiId")
+ @NotNull
+ @Size(max = 128)
+ private String apiId = null;
+
+ @JsonProperty("ver")
+ @NotNull
+ @Size(max = 32)
+ private String ver = null;
+
+ @JsonProperty("ts")
+ @NotNull
+ private Long ts = null;
+
+ @JsonProperty("resMsgId")
+ private String resMsgId = null;
+
+ @JsonProperty("msgId")
+ @Size(max = 256)
+ private String msgId = null;
+
+ @JsonProperty("status")
+ @NotNull
+ private ResponseStatusEnum status = null;
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/ResponseInfoFactory.java b/services/id-gen-service/src/main/java/org/egov/id/model/ResponseInfoFactory.java
new file mode 100644
index 000000000..1e91de7ae
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/ResponseInfoFactory.java
@@ -0,0 +1,22 @@
+package org.egov.id.model;
+
+import org.springframework.stereotype.Service;
+
+/**
+ * ResponseInfoFactory
+ *
+ * @author Narendra
+ *
+ */
+@Service
+public class ResponseInfoFactory {
+ public ResponseInfo createResponseInfoFromRequestInfo(RequestInfo requestInfo, Boolean success) {
+ String apiId = requestInfo.getApiId();
+ String ver = requestInfo.getVer();
+ Long ts = requestInfo.getTs();
+ String resMsgId = "uief87324"; // FIXME : Hard-coded
+ String msgId = requestInfo.getMsgId();
+ ResponseStatusEnum responseStatus = success ? ResponseStatusEnum.SUCCESSFUL : ResponseStatusEnum.FAILED;
+ return new ResponseInfo(apiId, ver, ts, resMsgId, msgId, responseStatus);
+ }
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/ResponseStatusEnum.java b/services/id-gen-service/src/main/java/org/egov/id/model/ResponseStatusEnum.java
new file mode 100644
index 000000000..04c873dfa
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/ResponseStatusEnum.java
@@ -0,0 +1,35 @@
+package org.egov.id.model;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+/**
+ * status of request processing - to be enhanced in futuer to include INPROGRESS
+ */
+public enum ResponseStatusEnum {
+ SUCCESSFUL("SUCCESSFUL"),
+
+ FAILED("FAILED");
+
+ private String value;
+
+ ResponseStatusEnum(String value) {
+ this.value = value;
+ }
+
+ @Override
+ @JsonValue
+ public String toString() {
+ return String.valueOf(value);
+ }
+
+ @JsonCreator
+ public static ResponseStatusEnum fromValue(String text) {
+ for (ResponseStatusEnum b : ResponseStatusEnum.values()) {
+ if (String.valueOf(b.value).equals(text)) {
+ return b;
+ }
+ }
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/Role.java b/services/id-gen-service/src/main/java/org/egov/id/model/Role.java
new file mode 100644
index 000000000..fc62d3eb0
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/Role.java
@@ -0,0 +1,30 @@
+package org.egov.id.model;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * minimal representation of the Roles in the system to be carried along in
+ * UserInfo with RequestInfo meta data. Actual authorization service to extend
+ * this to have more role related attributes Author : Narendra
+ */
+@Setter
+@Getter
+@AllArgsConstructor
+@NoArgsConstructor
+public class Role {
+ @JsonProperty("name")
+ @NotNull
+ @Size(max = 64)
+ private String name = null;
+
+ @JsonProperty("description")
+ private String description = null;
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/TenantRole.java b/services/id-gen-service/src/main/java/org/egov/id/model/TenantRole.java
new file mode 100644
index 000000000..da647d6a8
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/TenantRole.java
@@ -0,0 +1,33 @@
+package org.egov.id.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.validation.constraints.NotNull;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * User role carries the tenant related role information for the user. A user
+ * can have multiple roles per tenant based on the need of the tenant. A user
+ * may also have multiple roles for multiple tenants. Author : Narendra
+ */
+
+@Setter
+@Getter
+@AllArgsConstructor
+@NoArgsConstructor
+public class TenantRole {
+ @JsonProperty("tenantId")
+ @NotNull
+ private String tenantId = null;
+
+ @JsonProperty("roles")
+ @NotNull
+ private List roles = new ArrayList();
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/model/UserInfo.java b/services/id-gen-service/src/main/java/org/egov/id/model/UserInfo.java
new file mode 100644
index 000000000..8615ee79f
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/model/UserInfo.java
@@ -0,0 +1,55 @@
+package org.egov.id.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * This is acting ID token of the authenticated user on the server. Any value
+ * provided by the clients will be ignored and actual user based on authtoken
+ * will be used on the server. Author : Narendra
+ */
+
+@Setter
+@Getter
+@AllArgsConstructor
+@NoArgsConstructor
+public class UserInfo {
+ @JsonProperty("tenantId")
+ @Size(max=256)
+ @NotNull
+ private String tenantId = null;
+
+ @JsonProperty("id")
+ private Integer id = null;
+
+ @JsonProperty("username")
+ @Size(max=64)
+ @NotNull
+ private String username = null;
+
+ @JsonProperty("mobile")
+ @Pattern(regexp = "^[0-9]{10}$", message = "MobileNumber should be 10 digit number")
+ private String mobile = null;
+
+ @JsonProperty("email")
+ @Size(max=128)
+ private String email = null;
+
+ @JsonProperty("primaryrole")
+ @NotNull
+ private List primaryrole = new ArrayList();
+
+ @JsonProperty("additionalroles")
+ private List additionalroles = new ArrayList();
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/service/IdGenerationService.java b/services/id-gen-service/src/main/java/org/egov/id/service/IdGenerationService.java
new file mode 100644
index 000000000..b8cfdb556
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/service/IdGenerationService.java
@@ -0,0 +1,463 @@
+package org.egov.id.service;
+
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.sql.DataSource;
+
+import lombok.extern.slf4j.Slf4j;
+import org.egov.id.config.PropertiesManager;
+import org.egov.id.masterdata.MasterDataProvider;
+import org.egov.id.masterdata.provider.DBMasterDataProvider;
+import org.egov.id.model.IDSeqOverflowException;
+import org.egov.id.model.IdGenerationRequest;
+import org.egov.id.model.IdGenerationResponse;
+import org.egov.id.model.IdRequest;
+import org.egov.id.model.IdResponse;
+import org.egov.id.model.InvalidIDFormatException;
+import org.egov.id.model.RequestInfo;
+import org.egov.id.model.ResponseInfoFactory;
+import org.egov.tracer.model.CustomException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.jdbc.BadSqlGrammarException;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+
+/**
+ * Description : IdGenerationService have methods related to the IdGeneration
+ *
+ * @author Pavan Kumar Kamma
+ */
+@Service
+@Slf4j
+public class IdGenerationService {
+
+ @Autowired
+ DataSource dataSource;
+
+ @Autowired
+ PropertiesManager propertiesManager;
+
+ @Autowired
+ private ResponseInfoFactory responseInfoFactory;
+
+ @Autowired
+ @Qualifier("masterDataProvider")
+ private MasterDataProvider masterDataProvider;
+
+ @Autowired
+ @Qualifier("DBMasterDataProvider")
+ private DBMasterDataProvider dbMasterDataProvider;
+
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+
+ // by default 'idformat' will be taken from MDMS. Change value of 'ismdms.on' to 'false'
+ // in application.properties to get data from DB instead.
+ @Value("${idformat.from.mdms}")
+ public boolean idFormatFromMDMS;
+
+ // By default, the auto create sequence is disabled
+ @Value("${autocreate.new.seq}")
+ public boolean autoCreateNewSeq;
+
+
+ //default count value
+ public Integer defaultCount = 1;
+
+
+ /**
+ * Description : This method to generate idGenerationResponse
+ *
+ * @param idGenerationRequest
+ * @return idGenerationResponse
+ * @throws Exception
+ */
+
+ public IdGenerationResponse generateIdResponse(IdGenerationRequest idGenerationRequest) throws Exception {
+
+ RequestInfo requestInfo = idGenerationRequest.getRequestInfo();
+ List idRequests = idGenerationRequest.getIdRequests();
+ List idResponses = new LinkedList<>();
+
+ IdGenerationResponse idGenerationResponse = new IdGenerationResponse();
+
+ for (IdRequest idRequest : idRequests) {
+ List generatedId = generateIdFromIdRequest(idRequest, requestInfo);
+ for (String ListOfIds : generatedId) {
+ IdResponse idResponse = new IdResponse();
+ idResponse.setId(ListOfIds);
+ idResponses.add(idResponse);
+ }
+ idGenerationResponse.setIdResponses(idResponses);
+ }
+ idGenerationResponse.setResponseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(requestInfo, true));
+
+ return idGenerationResponse;
+
+ }
+
+ ;
+
+ /**
+ * Description : This method to generate id
+ *
+ * @param idRequest
+ * @param requestInfo
+ * @return generatedId
+ * @throws Exception
+ */
+ private List generateIdFromIdRequest(IdRequest idRequest, RequestInfo requestInfo) throws Exception {
+
+ List generatedId = new LinkedList<>();
+ boolean autoCreateNewSeqFlag = false;
+ if (!StringUtils.isEmpty(idRequest.getIdName()))
+ {
+ // If IDName is specified then check if it is defined in MDMS
+ String idFormat = getIdFormatFinal(idRequest, requestInfo);
+
+ // If the idname is defined then the format should be used
+ // else fallback to the format in the request itself
+ if (!StringUtils.isEmpty(idFormat)){
+ idRequest.setFormat(idFormat);
+ autoCreateNewSeqFlag=true;
+ }else if(StringUtils.isEmpty(idFormat)){
+ autoCreateNewSeqFlag=false;
+ }
+ }
+
+ if (StringUtils.isEmpty(idRequest.getFormat()))
+ throw new CustomException("ID_NOT_FOUND",
+ "No Format is available in the MDMS for the given name and tenant");
+
+ return getFormattedId(idRequest, requestInfo,autoCreateNewSeqFlag);
+ }
+
+
+ /**
+ * Description : This method to generate Id when format is unknown and select MDMS or DB.
+ *
+ * @param idRequest
+ * @param requestInfo
+ * @return generatedId
+ * @throws Exception
+ */
+ private String getIdFormatFinal(IdRequest idRequest, RequestInfo requestInfo) throws Exception {
+
+ String idFormat = null;
+ try{
+ if (idFormatFromMDMS) {
+ idFormat = masterDataProvider.getIdFormat(requestInfo, idRequest); //from MDMS
+ } else {
+ idFormat = dbMasterDataProvider.getIdFormat(requestInfo, idRequest); //from DB
+ }
+ }catch(Exception ex){
+ if(StringUtils.isEmpty(idFormat)){
+ throw new CustomException("ID_NOT_FOUND",
+ "No Format is available in the MDMS for the given name and tenant");
+ }
+ log.error("Format returned NULL from both MDMS and DB",ex);
+ }
+ return idFormat;
+ }
+
+ /**
+ * Description : This method to retrieve Id format from DB
+ *
+ * @param idRequest
+ * @param requestInfo
+ * @return idFormat
+ * @throws Exception
+ */
+ private String getIdFormatfromDB(IdRequest idRequest, RequestInfo requestInfo) throws Exception {
+ // connection and prepared statement
+
+ String idFormat = null;
+ try {
+ String idName = idRequest.getIdName();
+ String tenantId = idRequest.getTenantId();
+ // select the id format from the id generation table
+ StringBuffer idSelectQuery = new StringBuffer();
+ idSelectQuery.append("SELECT format FROM id_generator ").append(" WHERE idname=? and tenantid=?");
+
+ String rs = jdbcTemplate.queryForObject(idSelectQuery.toString(),new Object[]{idName,tenantId}, String.class);
+ if (!StringUtils.isEmpty(rs)) {
+ idFormat = rs;
+ } else {
+ // querying for the id format with idname
+ StringBuffer idNameQuery = new StringBuffer();
+ idNameQuery.append("SELECT format FROM id_generator ").append(" WHERE idname=?");
+ rs = jdbcTemplate.queryForObject(idSelectQuery.toString(),new Object[]{idName}, String.class);
+ if (!StringUtils.isEmpty(rs))
+ idFormat = rs;
+ }
+ } catch (Exception ex){
+ log.error("SQL error while trying to retrive format from DB",ex);
+ }
+ return idFormat;
+ }
+
+ /**
+ * Description : This method to generate Id when format is known
+ *
+ * @param idRequest
+ * @param requestInfo
+ * @return formattedId
+ * @throws Exception
+ */
+
+ private List getFormattedId(IdRequest idRequest, RequestInfo requestInfo, boolean autoCreateNewSeqFlag) throws Exception {
+ List idFormatList = new LinkedList();
+ String idFormat = idRequest.getFormat();
+
+ try{
+ if (!StringUtils.isEmpty(idFormat.trim()) && !StringUtils.isEmpty(idRequest.getTenantId())) {
+ idFormat = idFormat.replace("[tenantid]", idRequest.getTenantId());
+ idFormat = idFormat.replace("[tenant_id]", idRequest.getTenantId().replace(".", "_"));
+ idFormat = idFormat.replace("[TENANT_ID]", idRequest.getTenantId().replace(".", "_").toUpperCase());
+ }
+ }catch (Exception ex){
+ if (StringUtils.isEmpty(idFormat)) {
+ throw new CustomException("IDGEN_FORMAT_ERROR", "Blank format is not allowed");
+ }
+ }
+
+ List matchList = new ArrayList();
+
+ Pattern regExpPattern = Pattern.compile("\\[(.*?)\\]");
+ Matcher regExpMatcher = regExpPattern.matcher(idFormat);
+
+ Integer count = getCount(idRequest);
+
+ while (regExpMatcher.find()) {// Finds Matching Pattern in String
+ matchList.add(regExpMatcher.group(1));// Fetching Group from String
+ }
+
+ HashMap> sequences = new HashMap<>();
+ String idFormatTemplate = idFormat;
+ String cityName = null;
+
+ for (int i = 0; i < count; i++) {
+ idFormat = idFormatTemplate;
+
+ for (String attributeName : matchList) {
+
+ if (attributeName.substring(0, 3).equalsIgnoreCase("seq")) {
+ if (!sequences.containsKey(attributeName)) {
+ sequences.put(attributeName, generateSequenceNumber(attributeName, requestInfo, idRequest,autoCreateNewSeqFlag));
+ }
+ idFormat = idFormat.replace("[" + attributeName + "]", sequences.get(attributeName).get(i));
+ } else if (attributeName.substring(0, 2).equalsIgnoreCase("fy")) {
+ idFormat = idFormat.replace("[" + attributeName + "]",
+ generateFinancialYearDateFormat(attributeName, requestInfo));
+ } else if (attributeName.substring(0, 2).equalsIgnoreCase("cy")) {
+ idFormat = idFormat.replace("[" + attributeName + "]",
+ generateCurrentYearDateFormat(attributeName, requestInfo));
+ } else if (attributeName.substring(0, 4).equalsIgnoreCase("city")) {
+ if (cityName == null) {
+ cityName = masterDataProvider.getCity(requestInfo, idRequest);
+ }
+ idFormat = idFormat.replace("[" + attributeName + "]", cityName);
+ } else {
+ idFormat = idFormat.replace("[" + attributeName + "]", generateRandomText(attributeName, requestInfo));
+ }
+ }
+ idFormatList.add(idFormat);
+ }
+
+ return idFormatList;
+ }
+
+ /**
+ * Description : This method to generate current financial year in given
+ * format
+ *
+ * @param requestInfo
+ * @return formattedDate
+ */
+ private String generateFinancialYearDateFormat(String financialYearFormat, RequestInfo requestInfo) {
+ try {
+
+ Date date = new Date();
+ financialYearFormat = financialYearFormat.substring(financialYearFormat.indexOf(":") + 1);
+ financialYearFormat = financialYearFormat.trim();
+ String currentFinancialYear = null;
+ String[] financialYearPatternArray;
+ financialYearPatternArray = financialYearFormat.split("-");
+ int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
+ int preYear = 0;
+ int postYear = 0;
+
+ for (String yearPattern : financialYearPatternArray) {
+
+ String formattedYear = null;
+ SimpleDateFormat formatter = new SimpleDateFormat(yearPattern.trim());
+ formattedYear = formatter.format(date);
+
+ if (financialYearPatternArray[0] == yearPattern) {
+ if (month > 3) {
+ preYear = Integer.valueOf(formattedYear);
+ } else {
+ preYear = Integer.valueOf(formattedYear) - 1;
+ }
+ } else {
+ if (month > 3) {
+ postYear = Integer.valueOf(formattedYear) + 1;
+ } else {
+ postYear = Integer.valueOf(formattedYear);
+ }
+ }
+ }
+ currentFinancialYear = preYear + "-" + postYear;
+ return currentFinancialYear;
+
+ } catch (Exception e) {
+
+ throw new CustomException("INVALID_FORMAT", "Error while generating financial year in provided format. Given format invalid.");
+ //throw new InvalidIDFormatException(propertiesManager.getInvalidIdFormat(), requestInfo);
+
+ }
+ }
+
+ /**
+ * Description : This method to generate current year date in given format
+ *
+ * @param dateFormat
+ * @param requestInfo
+ * @return formattedDate
+ */
+ private String generateCurrentYearDateFormat(String dateFormat, RequestInfo requestInfo) {
+ try {
+
+ Date date = new Date();
+ dateFormat = dateFormat.trim();
+ dateFormat = dateFormat.substring(dateFormat.indexOf(":") + 1);
+ dateFormat = dateFormat.trim();
+ SimpleDateFormat formatter = new SimpleDateFormat(dateFormat.trim());
+ formatter.setTimeZone(TimeZone.getTimeZone(propertiesManager.getTimeZone()));
+ String formattedDate = formatter.format(date);
+ return formattedDate;
+
+ } catch (Exception e) {
+
+ throw new CustomException("INVALID_FORMAT", "Error while generating current year in provided format. Given format invalid.");
+ //throw new InvalidIDFormatException(propertiesManager.getInvalidIdFormat(), requestInfo);
+
+ }
+ }
+
+ /**
+ * Description : This method to generate random text
+ *
+ * @param regex
+ * @param requestInfo
+ * @return randomTxt
+ */
+ private String generateRandomText(String regex, RequestInfo requestInfo) {
+ Random random = new Random();
+ List matchList = new ArrayList();
+ int length = 2;// default digits length
+ try {
+ Pattern.compile(regex);
+ } catch (Exception e) {
+ throw new CustomException("INVALID_REGEX", "Random text could not be generated. Invalid regex provided.");
+ //throw new InvalidIDFormatException(propertiesManager.getInvalidIdFormat(), requestInfo);
+ }
+ Matcher matcher = Pattern.compile("\\{(.*?)\\}").matcher(regex);
+ while (matcher.find()) {
+ matchList.add(matcher.group(1));
+ }
+ if (matchList.size() > 0) {
+ length = Integer.parseInt(matchList.get(0));
+ }
+ StringBuilder stringBuilder = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ stringBuilder.append(random.nextInt(25));
+ }
+ String randomTxt = stringBuilder.toString();
+ randomTxt = randomTxt.substring(0, length);
+ return randomTxt;
+ }
+
+ /**
+ * Description : This method to set default count value
+ *
+ * @param idRequest
+ * @return count
+ */
+ private Integer getCount(IdRequest idRequest) {
+ Integer count;
+ if (idRequest.getCount() == null) {
+ count = defaultCount;
+ } else {
+ count = idRequest.getCount();
+ }
+ return count;
+ }
+
+ /**
+ * Description : This method to generate sequence in DB
+ *
+ * @param sequenceName
+ */
+
+ private void createSequenceInDb(String sequenceName) throws Exception {
+
+ StringBuilder query = new StringBuilder("CREATE SEQUENCE ");
+ try {
+ query = query.append(sequenceName);
+ jdbcTemplate.execute(query.toString());
+ }catch (Exception ex){
+ log.error("Error creating new sequence",ex);
+ }
+ }
+
+ /**
+ * Description : This method to generate sequence number
+ *
+ * @param sequenceName
+ * @param requestInfo
+ * @return seqNumber
+ */
+ private List generateSequenceNumber(String sequenceName, RequestInfo requestInfo, IdRequest idRequest,boolean autoCreateNewSeqFlag) throws Exception {
+ Integer count = getCount(idRequest);
+ List sequenceList = new LinkedList<>();
+ List sequenceLists = new LinkedList<>();
+ // To generate a block of seq numbers
+
+ String sequenceSql = "SELECT NEXTVAL ('" + sequenceName + "') FROM GENERATE_SERIES(1,?)";
+ try {
+ sequenceList = jdbcTemplate.queryForList(sequenceSql, new Object[]{count}, String.class);
+ } catch (BadSqlGrammarException ex) {
+ if (ex.getSQLException().getSQLState().equals("42P01")){
+ try{
+ if (sequenceList.isEmpty() && autoCreateNewSeqFlag && autoCreateNewSeq){
+ createSequenceInDb(sequenceName);
+ sequenceList = jdbcTemplate.queryForList(sequenceSql, new Object[]{count}, String.class);
+ }
+ else if(sequenceList.isEmpty() && !autoCreateNewSeqFlag)
+ throw new CustomException("SEQ_DOES_NOT_EXIST","auto creation of seq is not allowed in DB");
+ }catch(Exception e) {
+ throw new CustomException("ERROR_CREATING_SEQ","Error occurred while auto creating seq in DB");
+ }
+ }else{
+ throw new CustomException("SEQ_NUMBER_ERROR","Error in retrieving seq number from DB");
+ }
+ } catch (Exception ex) {
+ log.error("Error retrieving seq number from DB",ex);
+ throw new CustomException("SEQ_NUMBER_ERROR","Error retrieving seq number from existing seq in DB");
+ }
+ for (String seqId : sequenceList) {
+ String seqNumber = String.format("%06d", Integer.parseInt(seqId)).toString();
+ sequenceLists.add(seqNumber.toString());
+ }
+ return sequenceLists;
+ }
+
+}
diff --git a/services/id-gen-service/src/main/java/org/egov/id/utils/Constants.java b/services/id-gen-service/src/main/java/org/egov/id/utils/Constants.java
new file mode 100644
index 000000000..4c65db328
--- /dev/null
+++ b/services/id-gen-service/src/main/java/org/egov/id/utils/Constants.java
@@ -0,0 +1,7 @@
+package org.egov.id.utils;
+
+public class Constants {
+ public static final String DEFAULT_MASTER_DATA_PROVIDER = "org.egov.id.masterdata.provider.WebServiceMasterDataProvider";
+
+ public static final String DEFAULT_TENANT_ID = "default";
+}
diff --git a/services/id-gen-service/src/main/resources/application.properties b/services/id-gen-service/src/main/resources/application.properties
new file mode 100644
index 000000000..973d559af
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/application.properties
@@ -0,0 +1,29 @@
+logging.pattern.console=%clr(%X{CORRELATION_ID:-}) %clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}
+
+invalid.input=Invalid input
+spring.datasource.url= jdbc:postgresql://localhost:5432/rainmaker_new
+spring.datasource.username=postgres
+spring.datasource.password=postgres
+id.generation.table=id_generator
+id.sequence.overflow=IDSeqOverFlow
+id.sequence.notfound=IDSeqNotFound
+id.invalid.format=InvalidIDFormat
+success=SUCCESSFULL
+failed=FAILED
+city.code.notfound=CityCodeNotFound
+idformat.from.mdms = true
+autocreate.new.seq = false
+autocreate.request.seq = false
+
+#Set context root
+server.context-path=/egov-idgen
+server.servlet.context-path=/egov-idgen
+server.port=8088
+
+management.endpoints.web.base-path=/
+
+egov.mdms.provider=org.egov.id.masterdata.provider.WebServiceMasterDataProvider
+mdms.service.host=https://dev.digit.org/
+mdms.service.search.uri=egov-mdms-service/v1/_search
+
+id.timezone=IST
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/Dockerfile b/services/id-gen-service/src/main/resources/db/Dockerfile
new file mode 100644
index 000000000..70b504661
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/Dockerfile
@@ -0,0 +1,13 @@
+FROM egovio/flyway:4.1.2
+
+COPY ./migration/main /flyway/sql
+
+COPY ./migration/dev /flyway/dev
+
+COPY ./migration/seed /flyway/seed
+
+COPY migrate.sh /usr/bin/migrate.sh
+
+RUN chmod +x /usr/bin/migrate.sh
+
+CMD ["/usr/bin/migrate.sh"]
diff --git a/services/id-gen-service/src/main/resources/db/migrate.sh b/services/id-gen-service/src/main/resources/db/migrate.sh
new file mode 100644
index 000000000..5593a173e
--- /dev/null
+++ b/services/id-gen-service/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 migrate
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/dev/V20170614122129__id_generation_insert_dml.sql b/services/id-gen-service/src/main/resources/db/migration/dev/V20170614122129__id_generation_insert_dml.sql
new file mode 100644
index 000000000..5a0f7e608
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/dev/V20170614122129__id_generation_insert_dml.sql
@@ -0,0 +1,2 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('propertytax.acknumber', 'ap.propertytax.acknumber' , 'AP-PT-[yyyy/MM/dd]-[SEQ_ACK_NUM]-[d{2}]', 1);
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('propertytax.assessmentnumber', 'mh.propertytax.assessmentnumber', 'MH-PT-[yyyy/MM/dd]-[SEQ_ASSESMNT_NUM]-[d{2}]', 2);
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/dev/V20170630131041__id_gen_insert_coll_data_dml.sql b/services/id-gen-service/src/main/resources/db/migration/dev/V20170630131041__id_gen_insert_coll_data_dml.sql
new file mode 100644
index 000000000..fbf44039d
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/dev/V20170630131041__id_gen_insert_coll_data_dml.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('collection.receiptno', 'default' , 'GN-CL-[yyyy/MM/dd]-[SEQ_COLL_RCPT_NUM]', 3);
diff --git a/services/id-gen-service/src/main/resources/db/migration/dev/V20170704152406__id_gen_insert_coll_data_dml.sql b/services/id-gen-service/src/main/resources/db/migration/dev/V20170704152406__id_gen_insert_coll_data_dml.sql
new file mode 100644
index 000000000..e6226d425
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/dev/V20170704152406__id_gen_insert_coll_data_dml.sql
@@ -0,0 +1,3 @@
+UPDATE id_generator set format = 'GN-CL-[cy:yyyy/MM/dd]-[SEQ_COLL_RCPT_NUM]' where sequencenumber=3;
+UPDATE id_generator set format = 'AP-PT-[cy:yyyy/MM/dd]-[SEQ_ACK_NUM]-[d{2}]' where sequencenumber=1;
+UPDATE id_generator set format = 'MH-PT-[fy:yyyy-yyyy]-[SEQ_ASSESMNT_NUM]-[d{2}]' where sequencenumber=2;
diff --git a/services/id-gen-service/src/main/resources/db/migration/dev/V20170724172717__alter_coll_id_format_dml.sql b/services/id-gen-service/src/main/resources/db/migration/dev/V20170724172717__alter_coll_id_format_dml.sql
new file mode 100644
index 000000000..423233df5
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/dev/V20170724172717__alter_coll_id_format_dml.sql
@@ -0,0 +1 @@
+update id_generator set format = '[cy:MM]/[fy:yyyy-yy]/[SEQ_COLL_RCPT_NUM]' where idname = 'collection.receiptno';
diff --git a/services/id-gen-service/src/main/resources/db/migration/dev/V20170807144114__id_gen_insert_collection_transaction_format.sql b/services/id-gen-service/src/main/resources/db/migration/dev/V20170807144114__id_gen_insert_collection_transaction_format.sql
new file mode 100644
index 000000000..0bf9e70ee
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/dev/V20170807144114__id_gen_insert_collection_transaction_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('collection.transactionno', 'default' , '[CITY.CODE][d{10}]', 4);
diff --git a/services/id-gen-service/src/main/resources/db/migration/dev/V20171020231801__id_gen_insert_swm_transaction_num_format.sql b/services/id-gen-service/src/main/resources/db/migration/dev/V20171020231801__id_gen_insert_swm_transaction_num_format.sql
new file mode 100644
index 000000000..fb4866fc4
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/dev/V20171020231801__id_gen_insert_swm_transaction_num_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.transaction.number', 'default', 'MH-SWM-TRN-[SEQ_SWM_TRN_NUM]', 1);
diff --git a/services/id-gen-service/src/main/resources/db/migration/dev/V20171223074937__id_gen_insert_egf_bill_num_format.sql b/services/id-gen-service/src/main/resources/db/migration/dev/V20171223074937__id_gen_insert_egf_bill_num_format.sql
new file mode 100644
index 000000000..7b55c20c4
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/dev/V20171223074937__id_gen_insert_egf_bill_num_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('egf.bill.default.number.format.name', 'default', 'MH-BILL-NUM-[SEQ_EGF_BILL_DFT_NUM]', 1);
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20170614121459__DDL_id_generation_create_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20170614121459__DDL_id_generation_create_ddl.sql
new file mode 100644
index 000000000..a4bc07168
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20170614121459__DDL_id_generation_create_ddl.sql
@@ -0,0 +1,13 @@
+CREATE TABLE id_generator
+(
+ id bigserial NOT NULL,
+ idname character varying(200) NOT NULL,
+ tenantid character varying(200) NOT NULL,
+ format character varying(200) NOT NULL,
+ sequencenumber integer NOT NULL,
+
+ CONSTRAINT pk_id_generator PRIMARY KEY (id)
+);
+CREATE SEQUENCE SEQ_ACK_NUM;
+CREATE SEQUENCE SEQ_ASSESMNT_NUM;
+
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20170630130913__create_collection_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20170630130913__create_collection_seq_ddl.sql
new file mode 100644
index 000000000..6177bb516
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20170630130913__create_collection_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_COLL_RCPT_NUM;
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20170713115259__create_upicnum_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20170713115259__create_upicnum_seq_ddl.sql
new file mode 100644
index 000000000..f53c9bb28
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20170713115259__create_upicnum_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_UPIC_NUM;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20170731222759__create_noticeno_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20170731222759__create_noticeno_seq_ddl.sql
new file mode 100644
index 000000000..74cfa39e4
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20170731222759__create_noticeno_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_ULB_CODE;
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20170816191759__create_tl_num_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20170816191759__create_tl_num_seq_ddl.sql
new file mode 100644
index 000000000..61a69586c
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20170816191759__create_tl_num_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_TL_NUM;
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20170817164130__create_employee_code_number_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20170817164130__create_employee_code_number_seq_ddl.sql
new file mode 100644
index 000000000..be5416098
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20170817164130__create_employee_code_number_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE seq_employee_code;
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20170826133659__create_tl_application_num_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20170826133659__create_tl_application_num_seq_ddl.sql
new file mode 100644
index 000000000..65196563f
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20170826133659__create_tl_application_num_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_TL_APP_NUM;
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171020231917__create_swm_transaction_num_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171020231917__create_swm_transaction_num_seq_ddl.sql
new file mode 100644
index 000000000..e7792c6c0
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171020231917__create_swm_transaction_num_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_SWM_TRN_NUM;
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171030111720__create_lcms_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171030111720__create_lcms_seq_ddl.sql
new file mode 100644
index 000000000..cb335bc90
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171030111720__create_lcms_seq_ddl.sql
@@ -0,0 +1,7 @@
+CREATE SEQUENCE SEQ_SUMMON_CODE;
+CREATE SEQUENCE SEQ_SUMMON_REFERENCE;
+CREATE SEQUENCE SEQ_CASE_REFERENCE;
+CREATE SEQUENCE SEQ_ADVOCATE_CODE;
+CREATE SEQUENCE SEQ_ADVOCATEPAYMENT_CODE;
+CREATE SEQUENCE SEQ_OPINION_CODE;
+
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171031140120__create_lcms_seq_voucher_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171031140120__create_lcms_seq_voucher_ddl.sql
new file mode 100644
index 000000000..97b217cfe
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171031140120__create_lcms_seq_voucher_ddl.sql
@@ -0,0 +1,2 @@
+CREATE SEQUENCE SEQ_VOUCHER_CODE;
+CREATE SEQUENCE SEQ_CASE_ADVOCATE;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171031155035__create_lcms_seq_parawise_comments.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171031155035__create_lcms_seq_parawise_comments.sql
new file mode 100644
index 000000000..f3828d2f5
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171031155035__create_lcms_seq_parawise_comments.sql
@@ -0,0 +1,4 @@
+CREATE SEQUENCE SEQ_NOTICE;
+CREATE SEQUENCE SEQ_REGISTER;
+CREATE SEQUENCE SEQ_PARAWISE_COMMENTS;
+CREATE SEQUENCE SEQ_HEARING_DETAILS;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171103163310__create_swm_contract_num_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171103163310__create_swm_contract_num_seq_ddl.sql
new file mode 100644
index 000000000..70bc30c59
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171103163310__create_swm_contract_num_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_SWM_CTRT_NUM;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171103163443__create_swm_vendor_num_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171103163443__create_swm_vendor_num_seq_ddl.sql
new file mode 100644
index 000000000..1824a1b4e
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171103163443__create_swm_vendor_num_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_SWM_VNDR_NUM;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171103164912__create_swm_contractor_num_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171103164912__create_swm_contractor_num_seq_ddl.sql
new file mode 100644
index 000000000..4e0f27851
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171103164912__create_swm_contractor_num_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_SWM_CTRTR_NUM;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171104162601__create_swm_vendor_contract_num_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171104162601__create_swm_vendor_contract_num_seq_ddl.sql
new file mode 100644
index 000000000..628061ec3
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171104162601__create_swm_vendor_contract_num_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_SWM_VNDR_CTRT_NUM;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171108112621__create_reference_evidence_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171108112621__create_reference_evidence_seq_ddl.sql
new file mode 100644
index 000000000..9cc923c1c
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171108112621__create_reference_evidence_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_REFERENCE_EVIDENCE;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171109001824__create_swm_vehicle_schedule_transaction_num_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171109001824__create_swm_vehicle_schedule_transaction_num_seq_ddl.sql
new file mode 100644
index 000000000..758cf1547
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171109001824__create_swm_vehicle_schedule_transaction_num_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_SWM_VS_TRN_NUM;
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171109145848__create_swm_supplier_num_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171109145848__create_swm_supplier_num_seq_ddl.sql
new file mode 100644
index 000000000..fbdf53ca7
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171109145848__create_swm_supplier_num_seq_ddl.sql
@@ -0,0 +1,3 @@
+DROP SEQUENCE SEQ_SWM_CTRTR_NUM;
+
+CREATE SEQUENCE SEQ_SWM_SPLR_NUM;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171110163419__create_swm_trip_num_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171110163419__create_swm_trip_num_seq_ddl.sql
new file mode 100644
index 000000000..8df6b9c57
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171110163419__create_swm_trip_num_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_SWM_VHL_TRIP_NUM;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171113174232__create_swm_vendor_paymentdetails_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171113174232__create_swm_vendor_paymentdetails_seq_ddl.sql
new file mode 100644
index 000000000..b722aa994
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171113174232__create_swm_vendor_paymentdetails_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_SWM_VENDOR_PAYMENT_NUM;
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171113175600__create_swm_sanitationstaff_target_number_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171113175600__create_swm_sanitationstaff_target_number_seq_ddl.sql
new file mode 100644
index 000000000..f40254e5b
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171113175600__create_swm_sanitationstaff_target_number_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_SWM_SNTS_TRGT_NUM;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171113233008__create_swm_staff_transaction_number_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171113233008__create_swm_staff_transaction_number_seq_ddl.sql
new file mode 100644
index 000000000..0d4bb6efb
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171113233008__create_swm_staff_transaction_number_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_SWM_STF_TRN_NUM;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171114104545__create_personal_details_seq.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171114104545__create_personal_details_seq.sql
new file mode 100644
index 000000000..0cbb92d36
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171114104545__create_personal_details_seq.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_PERSONAL_DETAILS;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171114104620__create_agency_seq.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171114104620__create_agency_seq.sql
new file mode 100644
index 000000000..93de84491
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171114104620__create_agency_seq.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_AGENCY;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171115210014__create_event_seq.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171115210014__create_event_seq.sql
new file mode 100644
index 000000000..fed0f6e7b
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171115210014__create_event_seq.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_EVENT;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20171223074921__create_egf_bill_default_number_format_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20171223074921__create_egf_bill_default_number_format_seq_ddl.sql
new file mode 100644
index 000000000..558e357b1
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20171223074921__create_egf_bill_default_number_format_seq_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_EGF_BILL_DFT_NUM;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20180206121802__create_swm_vehicle_maintenance_repair_transaction_number_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20180206121802__create_swm_vehicle_maintenance_repair_transaction_number_ddl.sql
new file mode 100644
index 000000000..694ead630
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20180206121802__create_swm_vehicle_maintenance_repair_transaction_number_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_SWM_VMR_TRN_NUM;
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20180207123336__create_swm_shift_code_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20180207123336__create_swm_shift_code_ddl.sql
new file mode 100644
index 000000000..3d97b843d
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20180207123336__create_swm_shift_code_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_SWM_SHIFT_CODE_NUM;
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20180531123523__create_propertytax_ack_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20180531123523__create_propertytax_ack_ddl.sql
new file mode 100644
index 000000000..f4ae6a9c0
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20180531123523__create_propertytax_ack_ddl.sql
@@ -0,0 +1,2 @@
+CREATE SEQUENCE SEQ_EG_PT_ACK;
+CREATE SEQUENCE SEQ_EG_PT_ASSM;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20180607123336__create_pg_txn_id_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20180607123336__create_pg_txn_id_ddl.sql
new file mode 100644
index 000000000..3fd91c437
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20180607123336__create_pg_txn_id_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_EG_PG_TXN;
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20180709180520__create_propertytax_assess_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20180709180520__create_propertytax_assess_ddl.sql
new file mode 100644
index 000000000..4a13ff456
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20180709180520__create_propertytax_assess_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_EG_PT_PTID;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20180920115635__create_tl_seq_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20180920115635__create_tl_seq_ddl.sql
new file mode 100644
index 000000000..3be7ae608
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20180920115635__create_tl_seq_ddl.sql
@@ -0,0 +1,2 @@
+CREATE SEQUENCE SEQ_EG_TL_APL;
+CREATE SEQUENCE SEQ_EG_PT_LN;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20181030123635__DELETE_DUPLICATES_AND_ALTER_PRIMARYKEY_ID_GEN_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20181030123635__DELETE_DUPLICATES_AND_ALTER_PRIMARYKEY_ID_GEN_ddl.sql
new file mode 100644
index 000000000..cb399a4d6
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20181030123635__DELETE_DUPLICATES_AND_ALTER_PRIMARYKEY_ID_GEN_ddl.sql
@@ -0,0 +1,9 @@
+
+DELETE FROM id_generator WHERE id IN (SELECT id FROM id_generator gen INNER JOIN (SELECT count(*) as count, tenantid, idname FROM id_generator GROUP BY idname, tenantid) gencount
+
+ON gen.idname = gencount.idname AND gen.tenantid = gencount.tenantid WHERE count > 1);
+
+ALTER TABLE id_generator DROP CONSTRAINT pk_id_generator;
+
+ALTER TABLE id_generator ADD CONSTRAINT pk_id_generator PRIMARY KEY (idname, tenantid);
+
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20190129174853__create_hrms_empcode_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20190129174853__create_hrms_empcode_ddl.sql
new file mode 100644
index 000000000..9f6101dbb
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20190129174853__create_hrms_empcode_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE SEQ_EG_HRMS_EMP_CODE;
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20190520164710__UC_SEQ_ddl.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20190520164710__UC_SEQ_ddl.sql
new file mode 100644
index 000000000..3a0b66be0
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20190520164710__UC_SEQ_ddl.sql
@@ -0,0 +1 @@
+CREATE SEQUENCE seq_uc_demand_consumer_code;
diff --git a/services/id-gen-service/src/main/resources/db/migration/main/V20231019152045__createtenant_citycode.sql b/services/id-gen-service/src/main/resources/db/migration/main/V20231019152045__createtenant_citycode.sql
new file mode 100644
index 000000000..229e93072
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/main/V20231019152045__createtenant_citycode.sql
@@ -0,0 +1,8 @@
+CREATE TABLE IF NOT EXISTS tenantid_citycode
+(
+ id bigserial NOT NULL,
+ tenantid text NOT NULL,
+ citycode text NOT NULL,
+ CONSTRAINT pk_tenantid_citycode PRIMARY KEY (id),
+ CONSTRAINT uk_tenantid UNIQUE (tenantid)
+)
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20170829170804__collection_idgen_formats.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20170829170804__collection_idgen_formats.sql
new file mode 100644
index 000000000..180077839
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20170829170804__collection_idgen_formats.sql
@@ -0,0 +1,10 @@
+DROP SEQUENCE SEQ_COLL_RCPT_NUM;
+
+CREATE SEQUENCE SEQ_COLL_RCPT_NUM;
+
+delete from id_generator where idname in ('collection.receiptno','collection.transactionno') and tenantid='default';
+
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('collection.receiptno', 'default' , '[cy:MM]/[fy:yyyy-yy]/[SEQ_COLL_RCPT_NUM]', 3);
+
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('collection.transactionno', 'default' , '[CITY.CODE][d{10}]', 4);
+
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20171024151617__id_gen_insert_swm_transaction_num_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20171024151617__id_gen_insert_swm_transaction_num_format.sql
new file mode 100644
index 000000000..fb4866fc4
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20171024151617__id_gen_insert_swm_transaction_num_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.transaction.number', 'default', 'MH-SWM-TRN-[SEQ_SWM_TRN_NUM]', 1);
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20171103163517__id_gen_insert_swm_contract_num_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20171103163517__id_gen_insert_swm_contract_num_format.sql
new file mode 100644
index 000000000..1049aaa63
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20171103163517__id_gen_insert_swm_contract_num_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.contract.number', 'default', 'MH-SWM-CTRT-[SEQ_SWM_CTRT_NUM]', 1);
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20171103163533__id_gen_insert_swm_vendor_num_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20171103163533__id_gen_insert_swm_vendor_num_format.sql
new file mode 100644
index 000000000..e78096c19
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20171103163533__id_gen_insert_swm_vendor_num_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.vendor.number', 'default', 'MH-SWM-VNDR-[SEQ_SWM_VNDR_NUM]', 1);
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20171103164849__id_gen_insert_swm_contractor_num_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20171103164849__id_gen_insert_swm_contractor_num_format.sql
new file mode 100644
index 000000000..639ccadbd
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20171103164849__id_gen_insert_swm_contractor_num_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.contractor.number', 'default', 'MH-SWM-CTRTR-[SEQ_SWM_CTRTR_NUM]', 1);
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20171104162628__id_gen_insert_swm_vendor_contract_num_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20171104162628__id_gen_insert_swm_vendor_contract_num_format.sql
new file mode 100644
index 000000000..802689a04
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20171104162628__id_gen_insert_swm_vendor_contract_num_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.vendor.contract.number', 'default', 'MH-SWM-VNDR-CTRT-[SEQ_SWM_VNDR_CTRT_NUM]', 1);
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20171109001842__id_gen_insert_swm_vehicle_schedule_num_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20171109001842__id_gen_insert_swm_vehicle_schedule_num_format.sql
new file mode 100644
index 000000000..932e8d811
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20171109001842__id_gen_insert_swm_vehicle_schedule_num_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.vehicleschedule.transaction.number', 'default', 'MH-SWM-VS-TRN-[SEQ_SWM_VS_TRN_NUM]', 1);
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20171109145834__id_gen_insert_swm_supplier_num_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20171109145834__id_gen_insert_swm_supplier_num_format.sql
new file mode 100644
index 000000000..3a74360ae
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20171109145834__id_gen_insert_swm_supplier_num_format.sql
@@ -0,0 +1,3 @@
+delete from id_generator where idname = 'swm.contractor.number' and tenantId= 'default';
+
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.supplier.number', 'default', 'MH-SWM-SPLR-[SEQ_SWM_SPLR_NUM]', 1);
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20171110163435__id_gen_insert_swm_vehicle_trip_num_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20171110163435__id_gen_insert_swm_vehicle_trip_num_format.sql
new file mode 100644
index 000000000..f44a76c17
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20171110163435__id_gen_insert_swm_vehicle_trip_num_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.vehicle.trip.number', 'default', 'MH-SWM-VHL-TRIP-[SEQ_SWM_VHL_TRIP_NUM]', 1);
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20171113174601__id_gen_insert_swm_vendor_paymentdetails_num_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20171113174601__id_gen_insert_swm_vendor_paymentdetails_num_format.sql
new file mode 100644
index 000000000..b2797f400
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20171113174601__id_gen_insert_swm_vendor_paymentdetails_num_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.vendor.paymentdetails.paymentno', 'default', 'MH-SWM-VNDR-PMNT-[SEQ_SWM_VENDOR_PAYMENT_NUM]', 1);
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20171113175542__id_gen_insert_swm_sanitationstaff_target_number_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20171113175542__id_gen_insert_swm_sanitationstaff_target_number_format.sql
new file mode 100644
index 000000000..bd9ce1c2a
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20171113175542__id_gen_insert_swm_sanitationstaff_target_number_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.sanitationstaff.target.number', 'default', 'MH-SWM-SNTS-TRGT-[SEQ_SWM_SNTS_TRGT_NUM]', 1);
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20171113232951__id_gen_insert_swm_staff_transaction_number_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20171113232951__id_gen_insert_swm_staff_transaction_number_format.sql
new file mode 100644
index 000000000..1aeac1b4e
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20171113232951__id_gen_insert_swm_staff_transaction_number_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.staff.schedule.transaction.number', 'default', 'MH-SWM-STF-TRN-[SEQ_SWM_STF_TRN_NUM]', 1);
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20171223074952__id_gen_insert_egf_bill_num_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20171223074952__id_gen_insert_egf_bill_num_format.sql
new file mode 100644
index 000000000..7b55c20c4
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20171223074952__id_gen_insert_egf_bill_num_format.sql
@@ -0,0 +1 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('egf.bill.default.number.format.name', 'default', 'MH-BILL-NUM-[SEQ_EGF_BILL_DFT_NUM]', 1);
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20180206122754__id_gen_insert_swm_vehicle_maintenance_or_repair_transaction_number_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20180206122754__id_gen_insert_swm_vehicle_maintenance_or_repair_transaction_number_format.sql
new file mode 100644
index 000000000..2aef98b72
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20180206122754__id_gen_insert_swm_vehicle_maintenance_or_repair_transaction_number_format.sql
@@ -0,0 +1,2 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.vehicle.maintenance.repair.transaction.number', 'default', 'MH-SWM-VMR-TRN-[SEQ_SWM_VMR_TRN_NUM]', 1);
+
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20180207123352__id_gen_insert_swm_shift_code_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20180207123352__id_gen_insert_swm_shift_code_format.sql
new file mode 100644
index 000000000..cf31382ef
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20180207123352__id_gen_insert_swm_shift_code_format.sql
@@ -0,0 +1,2 @@
+INSERT INTO id_generator(idname, tenantid, format, sequencenumber) VALUES ('swm.shift.code', 'default', 'MH-SWM-SHIFT-CODE-[SEQ_SWM_SHIFT_CODE_NUM]', 1);
+
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20180209105537__id_gen_insert_swm_shift_id_format.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20180209105537__id_gen_insert_swm_shift_id_format.sql
new file mode 100644
index 000000000..57f1c2761
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20180209105537__id_gen_insert_swm_shift_id_format.sql
@@ -0,0 +1 @@
+update id_generator set format='MH-SWM-SHIFT-ID-[SEQ_SWM_SHIFT_CODE_NUM]' where format ='MH-SWM-SHIFT-CODE-[SEQ_SWM_SHIFT_CODE_NUM]';
\ No newline at end of file
diff --git a/services/id-gen-service/src/main/resources/db/migration/seed/V20231019162545__insert_into_tenant_citycode.sql b/services/id-gen-service/src/main/resources/db/migration/seed/V20231019162545__insert_into_tenant_citycode.sql
new file mode 100644
index 000000000..5f3cd7d11
--- /dev/null
+++ b/services/id-gen-service/src/main/resources/db/migration/seed/V20231019162545__insert_into_tenant_citycode.sql
@@ -0,0 +1 @@
+INSERT INTO tenantid_citycode(tenantid, citycode) VALUES ('default', 'default');
diff --git a/services/id-gen-service/src/test/java/org/egov/id/api/IdGenerationControllerTest.java b/services/id-gen-service/src/test/java/org/egov/id/api/IdGenerationControllerTest.java
new file mode 100644
index 000000000..da1593ec0
--- /dev/null
+++ b/services/id-gen-service/src/test/java/org/egov/id/api/IdGenerationControllerTest.java
@@ -0,0 +1,47 @@
+package org.egov.id.api;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.ArrayList;
+
+import org.egov.id.model.IdGenerationRequest;
+import org.egov.id.model.RequestInfo;
+import org.egov.id.service.IdGenerationService;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.servlet.ResultActions;
+import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+
+@ContextConfiguration(classes = {IdGenerationController.class})
+@ExtendWith(SpringExtension.class)
+class IdGenerationControllerTest {
+ @Autowired
+ private IdGenerationController idGenerationController;
+
+ @MockBean
+ private IdGenerationService idGenerationService;
+
+ @Test
+ void testGenerateIdResponse() throws Exception {
+ IdGenerationRequest idGenerationRequest = new IdGenerationRequest();
+ idGenerationRequest.setIdRequests(new ArrayList<>());
+ idGenerationRequest.setRequestInfo(new RequestInfo());
+ String content = (new ObjectMapper()).writeValueAsString(idGenerationRequest);
+ MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/_generate")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(content);
+ ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(this.idGenerationController)
+ .build()
+ .perform(requestBuilder);
+ actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound());
+ }
+}
+
diff --git a/services/id-gen-service/src/test/java/org/egov/id/exception/GlobalExceptionHandlerTest.java b/services/id-gen-service/src/test/java/org/egov/id/exception/GlobalExceptionHandlerTest.java
new file mode 100644
index 000000000..e8e48af22
--- /dev/null
+++ b/services/id-gen-service/src/test/java/org/egov/id/exception/GlobalExceptionHandlerTest.java
@@ -0,0 +1,92 @@
+package org.egov.id.exception;
+
+import lombok.extern.slf4j.Slf4j;
+import org.egov.id.config.PropertiesManager;
+import org.egov.id.model.Error;
+import org.egov.id.model.ErrorRes;
+import org.egov.id.model.ResponseInfo;
+import org.egov.id.model.ResponseStatusEnum;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.mockito.Mock;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.web.context.request.ServletWebRequest;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+
+@Slf4j
+class GlobalExceptionHandlerTest {
+
+ @Mock
+ private PropertiesManager propertiesManager;
+
+ void testUnknownException() {
+ GlobalExceptionHandler globalExceptionHandler = new GlobalExceptionHandler();
+ Exception ex = new Exception("An error occurred");
+ ErrorRes actualUnknownExceptionResult = globalExceptionHandler.unknownException(ex,
+ new ServletWebRequest(new MockHttpServletRequest()));
+ List errors = actualUnknownExceptionResult.getErrors();
+ assertEquals(1, errors.size());
+ ResponseInfo responseInfo = actualUnknownExceptionResult.getResponseInfo();
+ assertNull(responseInfo.getVer());
+ assertNull(responseInfo.getApiId());
+ assertNull(responseInfo.getResMsgId());
+ assertEquals(ResponseStatusEnum.FAILED, responseInfo.getStatus());
+ assertNull(responseInfo.getMsgId());
+ assertNull(responseInfo.getTs());
+ Error getResult = errors.get(0);
+ assertTrue(getResult.getFileds().isEmpty());
+ assertEquals("An error occurred", getResult.getMessage());
+ assertEquals("400 BAD_REQUEST", getResult.getCode());
+ assertNull(getResult.getDescription());
+ }
+
+ @Test
+ void testUnknownExceptionNull() {
+ GlobalExceptionHandler globalExceptionHandler = new GlobalExceptionHandler();
+ Exception ex = new Exception("nullValue");
+ ErrorRes actualUnknownExceptionResult = globalExceptionHandler.unknownException(ex,
+ new ServletWebRequest(new MockHttpServletRequest()));
+ List errors = actualUnknownExceptionResult.getErrors();
+ assertEquals(1, errors.size());
+ ResponseInfo responseInfo = actualUnknownExceptionResult.getResponseInfo();
+ assertNull(responseInfo.getVer());
+ assertNull(responseInfo.getApiId());
+ assertNull(responseInfo.getResMsgId());
+ assertEquals(ResponseStatusEnum.FAILED, responseInfo.getStatus());
+ assertNull(responseInfo.getMsgId());
+ assertNull(responseInfo.getTs());
+ Error getResult = errors.get(0);
+ assertTrue(getResult.getFileds().isEmpty());
+ assertEquals("nullValue", getResult.getMessage());
+ assertEquals("400 BAD_REQUEST", getResult.getCode());
+ assertNull(getResult.getDescription());
+ }
+
+ @Test
+ void testUnknownExceptionIDSeqNotFoundException() {
+ GlobalExceptionHandler globalExceptionHandler = new GlobalExceptionHandler();
+ Exception ex = new Exception("IDSeqNotFoundException");
+ ErrorRes actualUnknownExceptionResult = globalExceptionHandler.unknownException(ex,
+ new ServletWebRequest(new MockHttpServletRequest()));
+ List errors = actualUnknownExceptionResult.getErrors();
+ assertEquals(1, errors.size());
+ ResponseInfo responseInfo = actualUnknownExceptionResult.getResponseInfo();
+ assertNull(responseInfo.getVer());
+ assertNull(responseInfo.getApiId());
+ assertNull(responseInfo.getResMsgId());
+ assertEquals(ResponseStatusEnum.FAILED, responseInfo.getStatus());
+ assertNull(responseInfo.getMsgId());
+ assertNull(responseInfo.getTs());
+ Error getResult = errors.get(0);
+ assertTrue(getResult.getFileds().isEmpty());
+ assertEquals("IDSeqNotFoundException", getResult.getMessage());
+ assertEquals("400 BAD_REQUEST", getResult.getCode());
+ assertNull(getResult.getDescription());
+ }
+}
+
diff --git a/services/id-gen-service/src/test/java/org/egov/id/masterdata/provider/WebServiceMasterDataProviderTest.java b/services/id-gen-service/src/test/java/org/egov/id/masterdata/provider/WebServiceMasterDataProviderTest.java
new file mode 100644
index 000000000..25b8e5c5d
--- /dev/null
+++ b/services/id-gen-service/src/test/java/org/egov/id/masterdata/provider/WebServiceMasterDataProviderTest.java
@@ -0,0 +1,180 @@
+package org.egov.id.masterdata.provider;
+
+import org.egov.common.contract.response.ResponseInfo;
+import org.egov.id.model.IdRequest;
+import org.egov.mdms.model.MasterDetail;
+import org.egov.mdms.model.MdmsResponse;
+import org.egov.mdms.service.MdmsClientService;
+import org.egov.tracer.model.CustomException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+@ContextConfiguration(classes = {WebServiceMasterDataProvider.class})
+@ExtendWith(SpringExtension.class)
+class WebServiceMasterDataProviderTest {
+ @MockBean
+ private MdmsClientService mdmsClientService;
+
+ @Autowired
+ private WebServiceMasterDataProvider mdmsService;
+
+ @Test
+ void testGetMasterData() {
+ MdmsResponse mdmsResponse = new MdmsResponse();
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any())).thenReturn(mdmsResponse);
+ org.egov.id.model.RequestInfo requestInfo = new org.egov.id.model.RequestInfo();
+ assertSame(mdmsResponse, this.mdmsService.getMasterData(requestInfo, "42", new HashMap<>()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any());
+ }
+
+ @Test
+ void testGetMasterData2() {
+ MdmsResponse mdmsResponse = new MdmsResponse();
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any())).thenReturn(mdmsResponse);
+ assertSame(mdmsResponse, this.mdmsService.getMasterData(null, "42", new HashMap<>()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any());
+ }
+
+ @Test
+ void testGetMasterData4() {
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any())).thenThrow(new CustomException("Code", "An error occurred"));
+ org.egov.id.model.RequestInfo requestInfo = new org.egov.id.model.RequestInfo();
+ assertThrows(CustomException.class, () -> this.mdmsService.getMasterData(requestInfo, "42", new HashMap<>()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any());
+ }
+
+ @Test
+ void testGetCity() {
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any()))
+ .thenReturn(new MdmsResponse());
+ org.egov.id.model.RequestInfo requestInfo = new org.egov.id.model.RequestInfo();
+ assertThrows(CustomException.class, () -> this.mdmsService.getCity(requestInfo, new IdRequest()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any());
+ }
+
+ @Test
+ void testGetCity2() {
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any())).thenReturn(null);
+ org.egov.id.model.RequestInfo requestInfo = new org.egov.id.model.RequestInfo();
+ assertThrows(CustomException.class, () -> this.mdmsService.getCity(requestInfo, new IdRequest()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any());
+ }
+
+ @Test
+ void testGetCity3() {
+ ResponseInfo responseInfo = new ResponseInfo();
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (Map>) any()))
+ .thenReturn(new MdmsResponse(responseInfo, new HashMap<>()));
+ org.egov.id.model.RequestInfo requestInfo = new org.egov.id.model.RequestInfo();
+ assertThrows(CustomException.class, () -> this.mdmsService.getCity(requestInfo, new IdRequest()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (Map>) any());
+ }
+
+ @Test
+ void testGetCity4() {
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any()))
+ .thenReturn(new MdmsResponse());
+ assertThrows(CustomException.class, () -> this.mdmsService.getCity(null, new IdRequest()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any());
+ }
+
+ @Test
+ void testGetCity5() {
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any()))
+ .thenReturn(new MdmsResponse());
+ org.egov.id.model.RequestInfo requestInfo = mock(org.egov.id.model.RequestInfo.class);
+ assertThrows(CustomException.class, () -> this.mdmsService.getCity(requestInfo, new IdRequest()));
+ }
+
+ @Test
+ void testGetCity7() {
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any()))
+ .thenThrow(new CustomException("tenants", "An error occurred"));
+ org.egov.id.model.RequestInfo requestInfo = new org.egov.id.model.RequestInfo();
+ assertThrows(CustomException.class, () -> this.mdmsService.getCity(requestInfo, new IdRequest()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any());
+ }
+
+ @Test
+ void testGetIdFormat() {
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any()))
+ .thenReturn(new MdmsResponse());
+ org.egov.id.model.RequestInfo requestInfo = new org.egov.id.model.RequestInfo();
+ assertNull(this.mdmsService.getIdFormat(requestInfo, new IdRequest()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any());
+ }
+
+ @Test
+ void testGetIdFormat2() {
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any())).thenReturn(null);
+ org.egov.id.model.RequestInfo requestInfo = new org.egov.id.model.RequestInfo();
+ assertThrows(CustomException.class, () -> this.mdmsService.getIdFormat(requestInfo, new IdRequest()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any());
+ }
+
+ @Test
+ void testGetIdFormat3() {
+ ResponseInfo responseInfo = new ResponseInfo();
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (Map>) any()))
+ .thenReturn(new MdmsResponse(responseInfo, new HashMap<>()));
+ org.egov.id.model.RequestInfo requestInfo = new org.egov.id.model.RequestInfo();
+ assertNull(this.mdmsService.getIdFormat(requestInfo, new IdRequest()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (Map>) any());
+ }
+
+ @Test
+ void testGetIdFormat4() {
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any()))
+ .thenReturn(new MdmsResponse());
+ assertNull(this.mdmsService.getIdFormat(null, new IdRequest()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any());
+ }
+
+ @Test
+ void testGetIdFormat7() {
+ when(this.mdmsClientService.getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any()))
+ .thenThrow(new CustomException("tenants", "An error occurred"));
+ org.egov.id.model.RequestInfo requestInfo = new org.egov.id.model.RequestInfo();
+ assertThrows(CustomException.class, () -> this.mdmsService.getIdFormat(requestInfo, new IdRequest()));
+ verify(this.mdmsClientService).getMaster((org.egov.common.contract.request.RequestInfo) any(), (String) any(),
+ (java.util.Map>) any());
+ }
+}
+
diff --git a/services/id-gen-service/src/test/java/org/egov/id/service/IdGenerationServiceTest.java b/services/id-gen-service/src/test/java/org/egov/id/service/IdGenerationServiceTest.java
new file mode 100644
index 000000000..cb50c2ad6
--- /dev/null
+++ b/services/id-gen-service/src/test/java/org/egov/id/service/IdGenerationServiceTest.java
@@ -0,0 +1,164 @@
+package org.egov.id.service;
+
+import org.egov.id.model.IdGenerationRequest;
+import org.egov.id.model.IdRequest;
+import org.egov.id.model.RequestInfo;
+import org.egov.id.model.ResponseInfoFactory;
+import org.egov.tracer.model.CustomException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.*;
+@RunWith(SpringJUnit4ClassRunner.class)
+@ExtendWith(SpringExtension.class)
+
+class IdGenerationServiceTest {
+
+
+ @MockBean
+ ResponseInfoFactory responseInfoFactory;
+
+ @Test
+ void testGenerateIdResponse() throws Exception {
+
+ IdGenerationService idGenerationService = new IdGenerationService();
+
+ ArrayList idRequestList = new ArrayList<>();
+ idRequestList.add(new IdRequest());
+
+ IdGenerationRequest idGenerationRequest = new IdGenerationRequest();
+ idGenerationRequest.setIdRequests(idRequestList);
+ assertThrows(CustomException.class, () -> idGenerationService.generateIdResponse(idGenerationRequest));
+ }
+
+ @Test
+ void testGenerateIdResponse3() throws Exception {
+
+ IdGenerationService idGenerationService = new IdGenerationService();
+
+ ArrayList idRequestList = new ArrayList<>();
+ idRequestList.add(new IdRequest());
+ IdGenerationRequest idGenerationRequest = new IdGenerationRequest();
+ idGenerationRequest.setIdRequests(idRequestList);
+ assertThrows(CustomException.class, () -> idGenerationService.generateIdResponse(idGenerationRequest));
+
+ }
+
+ @Test
+ void testGenerateIdResponse4() throws Exception {
+ IdGenerationService idGenerationService = new IdGenerationService();
+
+ ArrayList idRequestList = new ArrayList<>();
+ idRequestList.add(new IdRequest());
+
+ IdGenerationRequest idGenerationRequest = new IdGenerationRequest();
+ idGenerationRequest.setIdRequests(idRequestList);
+ assertThrows(CustomException.class, () -> idGenerationService.generateIdResponse(idGenerationRequest));
+ }
+
+ @Test
+ void testGenerateIdResponseWithArguments() throws Exception {
+
+ IdGenerationService idGenerationService = new IdGenerationService();
+
+ ArrayList idRequestList = new ArrayList<>();
+ idRequestList.add(new IdRequest());
+
+ IdRequest idRequest = new IdRequest("Id Name", "42", "Format", 3);
+ idRequest.setFormat("\\[(.*?)\\]");
+
+ ArrayList idRequestList1 = new ArrayList<>();
+ idRequestList1.add(idRequest);
+ IdGenerationRequest idGenerationRequest = mock(IdGenerationRequest.class);
+ when(idGenerationRequest.getIdRequests()).thenReturn(idRequestList1);
+ when(idGenerationRequest.getRequestInfo()).thenReturn(new RequestInfo());
+ doNothing().when(idGenerationRequest).setIdRequests((List) any());
+ idGenerationRequest.setIdRequests(idRequestList);
+ assertThrows(CustomException.class, () -> idGenerationService.generateIdResponse(idGenerationRequest));
+ verify(idGenerationRequest).getIdRequests();
+ verify(idGenerationRequest).getRequestInfo();
+ verify(idGenerationRequest).setIdRequests((List) any());
+ }
+
+ @Test
+ void testGenerateIdResponseTenantIdNull() throws Exception {
+
+ IdGenerationService idGenerationService = new IdGenerationService();
+
+ ArrayList idRequestList = new ArrayList<>();
+ idRequestList.add(new IdRequest());
+
+ IdRequest idRequest = new IdRequest("Id Name", null, "Format", 3);
+ idRequest.setFormat("\\[(.*?)\\]");
+
+ ArrayList idRequestList1 = new ArrayList<>();
+ idRequestList1.add(idRequest);
+ IdGenerationRequest idGenerationRequest = mock(IdGenerationRequest.class);
+ when(idGenerationRequest.getIdRequests()).thenReturn(idRequestList1);
+ when(idGenerationRequest.getRequestInfo()).thenReturn(new RequestInfo());
+ doNothing().when(idGenerationRequest).setIdRequests((List) any());
+ idGenerationRequest.setIdRequests(idRequestList);
+ assertThrows(CustomException.class, () -> idGenerationService.generateIdResponse(idGenerationRequest));
+ verify(idGenerationRequest).getIdRequests();
+ verify(idGenerationRequest).getRequestInfo();
+ verify(idGenerationRequest).setIdRequests((List) any());
+ }
+
+ @Test
+ void testGenerateIdResponseNullCount() throws Exception {
+
+ IdGenerationService idGenerationService = new IdGenerationService();
+
+ ArrayList idRequestList = new ArrayList<>();
+ idRequestList.add(new IdRequest());
+
+ IdRequest idRequest = new IdRequest("Id Name", "42", "Format", null);
+ idRequest.setFormat("\\[(.*?)\\]");
+
+ ArrayList idRequestList1 = new ArrayList<>();
+ idRequestList1.add(idRequest);
+ IdGenerationRequest idGenerationRequest = mock(IdGenerationRequest.class);
+ when(idGenerationRequest.getIdRequests()).thenReturn(idRequestList1);
+ when(idGenerationRequest.getRequestInfo()).thenReturn(new RequestInfo());
+ doNothing().when(idGenerationRequest).setIdRequests((List) any());
+ idGenerationRequest.setIdRequests(idRequestList);
+ assertThrows(CustomException.class, () -> idGenerationService.generateIdResponse(idGenerationRequest));
+ verify(idGenerationRequest).getIdRequests();
+ verify(idGenerationRequest).getRequestInfo();
+ verify(idGenerationRequest).setIdRequests((List) any());
+ }
+
+ @Test
+ void testGenerateIdResponseIdnull() throws Exception {
+
+ IdGenerationService idGenerationService = new IdGenerationService();
+
+ ArrayList idRequestList = new ArrayList<>();
+ idRequestList.add(new IdRequest());
+
+ IdRequest idRequest = new IdRequest(null, "42", "Format", 3);
+ idRequest.setFormat("\\[(.*?)\\]");
+
+ ArrayList idRequestList1 = new ArrayList<>();
+ idRequestList1.add(idRequest);
+ IdGenerationRequest idGenerationRequest = mock(IdGenerationRequest.class);
+ when(idGenerationRequest.getIdRequests()).thenReturn(idRequestList1);
+ when(idGenerationRequest.getRequestInfo()).thenReturn(new RequestInfo());
+ doNothing().when(idGenerationRequest).setIdRequests((List) any());
+ idGenerationRequest.setIdRequests(idRequestList);
+ assertThrows(CustomException.class, () -> idGenerationService.generateIdResponse(idGenerationRequest));
+ verify(idGenerationRequest).getIdRequests();
+ verify(idGenerationRequest).getRequestInfo();
+ verify(idGenerationRequest).setIdRequests((List) any());
+ }
+
+}
+