From 160bffca6994571f5a38957452a59c1512c8be23 Mon Sep 17 00:00:00 2001 From: Manoj SP Date: Fri, 12 Aug 2022 09:51:39 +0530 Subject: [PATCH] [MOSIP-21290] Added util to remap duplicate uin and its vid to primary uin --- .../id-repository-uin-remap-util/README.md | 11 ++ .../id-repository-uin-remap-util/pom.xml | 126 +++++++++++++++++ .../remap/util/RemapMainApplication.java | 20 +++ .../remap/util/config/IdentityRepoConfig.java | 101 ++++++++++++++ .../remap/util/config/OpenApiProperties.java | 39 ++++++ .../remap/util/config/SwaggerConfig.java | 53 ++++++++ .../remap/util/config/VidRepoConfig.java | 98 ++++++++++++++ .../util/controller/RemapUtilController.java | 43 ++++++ .../util/dto/BaseRequestResponseDTO.java | 25 ++++ .../remap/util/dto/RequestDTO.java | 13 ++ .../remap/util/identity/entity/Uin.java | 111 +++++++++++++++ .../util/identity/entity/UinHashSalt.java | 47 +++++++ .../util/identity/entity/UinHistory.java | 111 +++++++++++++++ .../util/identity/repository/UinHRepo.java | 65 +++++++++ .../identity/repository/UinHashSaltRepo.java | 26 ++++ .../util/identity/repository/UinRepo.java | 64 +++++++++ .../remap/util/service/RemapUtilService.java | 128 ++++++++++++++++++ .../remap/util/vid/entity/Vid.java | 80 +++++++++++ .../remap/util/vid/entity/VidUinHashSalt.java | 47 +++++++ .../remap/util/vid/repository/VidRepo.java | 56 ++++++++ .../vid/repository/VidUinHashSaltRepo.java | 26 ++++ 21 files changed, 1290 insertions(+) create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/README.md create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/pom.xml create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/RemapMainApplication.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/IdentityRepoConfig.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/OpenApiProperties.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/SwaggerConfig.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/VidRepoConfig.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/controller/RemapUtilController.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/dto/BaseRequestResponseDTO.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/dto/RequestDTO.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/entity/Uin.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/entity/UinHashSalt.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/entity/UinHistory.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/repository/UinHRepo.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/repository/UinHashSaltRepo.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/repository/UinRepo.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/service/RemapUtilService.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/entity/Vid.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/entity/VidUinHashSalt.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/repository/VidRepo.java create mode 100644 deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/repository/VidUinHashSaltRepo.java diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/README.md b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/README.md new file mode 100644 index 000000000..0b924b596 --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/README.md @@ -0,0 +1,11 @@ +SWAGGER UI: http://localhost:8888/idrepository/v1/remap/swagger-ui/index.html?configUrl=/idrepository/v1/remap/v3/api-docs/swagger-config + +PATCH: http://localhost:8888/idrepository/v1/remap/remap + +REQUEST: +{ + "primaryUin": "4791867143", + "uinsToDeactivate": [ + "6207103247" + ] +} \ No newline at end of file diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/pom.xml b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/pom.xml new file mode 100644 index 000000000..3795c2faa --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/pom.xml @@ -0,0 +1,126 @@ + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.0.2.RELEASE + + io.mosip.idrepository + id-repository-uin-remap-util + 0.0.1-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.postgresql + postgresql + 42.2.2 + + + io.springfox + springfox-swagger2 + 2.9.2 + + + io.springfox + springfox-swagger-ui + 2.9.2 + + + org.springdoc + springdoc-openapi-ui + 1.5.10 + + + io.mosip.kernel + kernel-core + 1.2.0 + + + org.projectlombok + lombok + + + + + org.projectlombok + lombok + 1.18.20 + provided + + + + + + org.eclipse.jkube + kubernetes-maven-plugin + 1.7.0 + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + build-info + repackage + + + + + + + + + MPL 2.0 + https://www.mozilla.org/en-US/MPL/2.0/ + + + + + Mosip + mosip.emailnotifier@gmail.com + io.mosip + https://github.com/mosip + + + + + + com.fasterxml.jackson.core + jackson-databind + 2.12.1 + + + com.fasterxml.jackson.core + jackson-core + 2.12.1 + + + com.fasterxml.jackson.core + jackson-annotations + 2.12.1 + + + + + 11 + NodePort + 11 + 11 + Always + openjdk:11 + manojsp12/remaputil + + \ No newline at end of file diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/RemapMainApplication.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/RemapMainApplication.java new file mode 100644 index 000000000..3cd5b4dbd --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/RemapMainApplication.java @@ -0,0 +1,20 @@ +package io.mosip.idrepository.remap.util; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; + +/** + * @author Manoj SP + * + */ +@SpringBootApplication(exclude = { SecurityAutoConfiguration.class }) +@ComponentScan(basePackages = { "io.mosip.idrepository.remap.util.*" }) +public class RemapMainApplication { + + public static void main(String[] args) throws Exception { + SpringApplication.run(RemapMainApplication.class, args); + } + +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/IdentityRepoConfig.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/IdentityRepoConfig.java new file mode 100644 index 000000000..918527c55 --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/IdentityRepoConfig.java @@ -0,0 +1,101 @@ +package io.mosip.idrepository.remap.util.config; + +import java.util.HashMap; +import java.util.Map; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy; +import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +/** + * + * @author Manoj SP + */ +@Configuration +@EnableTransactionManagement +@EnableJpaRepositories(basePackages = { + "io.mosip.idrepository.remap.util.identity.repository" }, entityManagerFactoryRef = "identityEntityManager", transactionManagerRef = "identityJpaTransactionManager") +public class IdentityRepoConfig { + + /** The env. */ + @Autowired + private Environment env; + + /** + * Entity manager factory. + * + * @return the local container entity manager factory bean + */ + @Bean("identityEntityManager") + @Qualifier("identityEntityManager") + @Primary + public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Qualifier("identityDataSource") DataSource identityDataSource) { + LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(identityDataSource); + em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); + em.setPackagesToScan("io.mosip.idrepository.remap.util.identity.entity"); + em.setJpaPropertyMap(additionalProperties()); + return em; + } + + /** + * Data source. + * + * @return the data source + */ + @Bean("identityDataSource") + @Qualifier("identityDataSource") + public DataSource dataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setUrl(env.getProperty("mosip.idrepository.identity.db.url")); + dataSource.setUsername(env.getProperty("mosip.idrepository.identity.db.username")); + dataSource.setPassword(env.getProperty("mosip.idrepository.identity.db.password")); + dataSource.setDriverClassName(env.getProperty("mosip.idrepository.identity.db.driverClassName")); + dataSource.setSchema(env.getProperty("mosip.idrepository.identity.db.schemaName")); + return dataSource; + } + + /** + * Jpa transaction manager. + * + * @param emf the emf + * @return the jpa transaction manager + */ + @Bean("identityJpaTransactionManager") + @Qualifier("identityJpaTransactionManager") + @Primary + public JpaTransactionManager jpaTransactionManager(EntityManagerFactory emf, @Qualifier("identityDataSource") DataSource identityDataSource) { + JpaTransactionManager jpaTransactionManager = new JpaTransactionManager(); + jpaTransactionManager.setEntityManagerFactory(entityManagerFactory(identityDataSource).getObject()); + jpaTransactionManager.setDataSource(dataSource()); + return jpaTransactionManager; + } + + /** + * Additional properties. + * + * @return the map + */ + private Map additionalProperties() { + Map jpaProperties = new HashMap<>(); + jpaProperties.put("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName()); + jpaProperties.put("hibernate.physical_naming_strategy", SpringPhysicalNamingStrategy.class.getName()); + jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect"); + return jpaProperties; + } + +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/OpenApiProperties.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/OpenApiProperties.java new file mode 100644 index 000000000..68aa2eadd --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/OpenApiProperties.java @@ -0,0 +1,39 @@ +package io.mosip.idrepository.remap.util.config; +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import java.util.List; + +@Configuration +@ConfigurationProperties(prefix = "openapi") +@Data +public class OpenApiProperties { + private InfoProperty info; + private IdRepoVidServiceServer idRepoVidServiceServer; +} + +@Data +class InfoProperty { + private String title; + private String description; + private String version; + private LicenseProperty license; +} + +@Data +class LicenseProperty { + private String name; + private String url; +} + +@Data +class IdRepoVidServiceServer { + private List servers; +} + +@Data +class Server { + private String description; + private String url; +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/SwaggerConfig.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/SwaggerConfig.java new file mode 100644 index 000000000..55163e808 --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/SwaggerConfig.java @@ -0,0 +1,53 @@ +package io.mosip.idrepository.remap.util.config; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.servers.Server; + +@Configuration +public class SwaggerConfig { + + private static final Logger logger = LoggerFactory.getLogger(SwaggerConfig.class); + + @Bean + public OpenAPI openApi(OpenApiProperties openApiProperties) { + String msg = "Swagger open api, "; + OpenAPI api = new OpenAPI() + .components(new Components()); + if (null != openApiProperties.getInfo()) { + api.info(new Info() + .title(openApiProperties.getInfo().getTitle()) + .version(openApiProperties.getInfo().getVersion()) + .description(openApiProperties.getInfo().getDescription())); + if (null != openApiProperties.getInfo().getLicense()) { + api.getInfo().license(new License() + .name(openApiProperties.getInfo().getLicense().getName()) + .url(openApiProperties.getInfo().getLicense().getUrl())); + logger.info(msg + "info license property is added"); + } else { + logger.error(msg + "info license property is empty"); + } + logger.info(msg + "info property is added"); + } else { + logger.error(msg + "info property is empty"); + } + + if (null != openApiProperties.getIdRepoVidServiceServer().getServers()) { + openApiProperties.getIdRepoVidServiceServer().getServers().forEach(server -> { + api.addServersItem(new Server().description(server.getDescription()).url(server.getUrl())); + }); + logger.info(msg + "server property is added"); + } else { + logger.error(msg + "server property is empty"); + } + return api; + } + +} \ No newline at end of file diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/VidRepoConfig.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/VidRepoConfig.java new file mode 100644 index 000000000..1a5eea8cf --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/config/VidRepoConfig.java @@ -0,0 +1,98 @@ +package io.mosip.idrepository.remap.util.config; + +import java.util.HashMap; +import java.util.Map; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy; +import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +/** + * + * @author Manoj SP + */ +@Configuration +@EnableTransactionManagement +@EnableJpaRepositories(basePackages = { +"io.mosip.idrepository.remap.util.vid.repository" }, entityManagerFactoryRef = "vidEntityManager", transactionManagerRef = "vidJpaTransactionManager") +public class VidRepoConfig { + + /** The env. */ + @Autowired + private Environment env; + + /** + * Entity manager factory. + * + * @return the local container entity manager factory bean + */ + @Bean("vidEntityManager") + @Qualifier("vidEntityManager") + public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Qualifier("vidDataSource") DataSource vidDataSource) { + LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(vidDataSource); + em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); + em.setPackagesToScan("io.mosip.idrepository.remap.util.vid.entity"); + em.setJpaPropertyMap(additionalProperties()); + return em; + } + + /** + * Data source. + * + * @return the data source + */ + @Bean + @Qualifier("vidDataSource") + public DataSource dataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setUrl(env.getProperty("mosip.idrepository.vid.db.url")); + dataSource.setUsername(env.getProperty("mosip.idrepository.vid.db.username")); + dataSource.setPassword(env.getProperty("mosip.idrepository.vid.db.password")); + dataSource.setDriverClassName(env.getProperty("mosip.idrepository.vid.db.driverClassName")); + dataSource.setSchema(env.getProperty("mosip.idrepository.vid.db.schemaName")); + return dataSource; + } + + /** + * Jpa transaction manager. + * + * @param emf the emf + * @return the jpa transaction manager + */ + @Bean("vidJpaTransactionManager") + @Qualifier("vidJpaTransactionManager") + public JpaTransactionManager jpaTransactionManager(EntityManagerFactory emf, @Qualifier("vidDataSource") DataSource vidDataSource) { + JpaTransactionManager jpaTransactionManager = new JpaTransactionManager(); + jpaTransactionManager.setEntityManagerFactory(entityManagerFactory(vidDataSource).getObject()); + jpaTransactionManager.setDataSource(dataSource()); + return jpaTransactionManager; + } + + /** + * Additional properties. + * + * @return the map + */ + private Map additionalProperties() { + Map jpaProperties = new HashMap<>(); + jpaProperties.put("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName()); + jpaProperties.put("hibernate.physical_naming_strategy", SpringPhysicalNamingStrategy.class.getName()); + jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect"); + return jpaProperties; + } + +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/controller/RemapUtilController.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/controller/RemapUtilController.java new file mode 100644 index 000000000..3c6ba8367 --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/controller/RemapUtilController.java @@ -0,0 +1,43 @@ +package io.mosip.idrepository.remap.util.controller; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import io.mosip.idrepository.remap.util.dto.RequestDTO; +import io.mosip.idrepository.remap.util.service.RemapUtilService; +import io.mosip.kernel.core.exception.BaseCheckedException; +import io.mosip.kernel.core.exception.ServiceError; +import io.mosip.kernel.core.http.ResponseWrapper; + +@RestController +public class RemapUtilController { + + @Autowired + private RemapUtilService service; + + @PostMapping(path = "/remap", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity>> remap(@RequestBody RequestDTO request) + throws BaseCheckedException { + ResponseWrapper> responseWrapper = new ResponseWrapper<>(); + try { + Objects.requireNonNull(request); + Objects.requireNonNull(request.getPrimaryUin()); + Objects.requireNonNull(request.getUinsToDeactivate()); + Map> remapResponse = service.remap(request.getPrimaryUin(), request.getUinsToDeactivate()); + responseWrapper.setResponse(Map.of("status", "Remapping success", "metadata", remapResponse)); + return ResponseEntity.ok(responseWrapper); + } catch (Exception e) { + responseWrapper.setResponse(Map.of("status", "Remapping failed")); + responseWrapper.setErrors(List.of(new ServiceError("", e.getMessage()))); + return ResponseEntity.badRequest().body(responseWrapper); + } + } +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/dto/BaseRequestResponseDTO.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/dto/BaseRequestResponseDTO.java new file mode 100644 index 000000000..5c057319e --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/dto/BaseRequestResponseDTO.java @@ -0,0 +1,25 @@ +package io.mosip.idrepository.remap.util.dto; + +import java.util.List; + +import lombok.Data; + +/** + * The Class BaseRequestResponseDTO - base class containing fields for Id + * repository request and response. + * + * @author Manoj SP + */ +@Data +public class BaseRequestResponseDTO { + + /** The status. */ + private String status; + + /** The identity. */ + private Object identity; + + /** The documents. */ + + private List verifiedAttributes; +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/dto/RequestDTO.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/dto/RequestDTO.java new file mode 100644 index 000000000..470a5ffaa --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/dto/RequestDTO.java @@ -0,0 +1,13 @@ +package io.mosip.idrepository.remap.util.dto; + +import java.util.List; + +import lombok.Data; + +@Data +public class RequestDTO { + + private String primaryUin; + + private List uinsToDeactivate; +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/entity/Uin.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/entity/Uin.java new file mode 100644 index 000000000..c78647523 --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/entity/Uin.java @@ -0,0 +1,111 @@ +package io.mosip.idrepository.remap.util.identity.entity; + +import java.time.LocalDateTime; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.Table; + +import org.hibernate.annotations.Type; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * The Class Uin -Entity class for uin table. + * + * @author Manoj SP + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "uin", schema = "idrepo") +@Entity +public class Uin { + + /** The uin ref id. */ + @Id + @Column(insertable = false, updatable = false, nullable = false) + private String uinRefId; + + /** The uin. */ + private String uin; + + private String uinHash; + + /** The uin data. */ + @Lob + @Type(type = "org.hibernate.type.BinaryType") + @Getter(AccessLevel.NONE) + @Setter(AccessLevel.NONE) + private byte[] uinData; + + /** The uin data hash. */ + private String uinDataHash; + + /** The reg id. */ + private String regId; + + private String bioRefId; + + /** The status code. */ + private String statusCode; + + private String langCode; + + /** The created by. */ + @Column(name = "cr_by") + private String createdBy; + + /** The created date time. */ + @Column(name = "cr_dtimes") + private LocalDateTime createdDateTime; + + /** The updated by. */ + @Column(name = "upd_by") + private String updatedBy; + + /** The updated date time. */ + @Column(name = "upd_dtimes") + private LocalDateTime updatedDateTime; + + /** The is deleted. */ + private Boolean isDeleted; + + /** The deleted date time. */ + @Column(name = "del_dtimes") + private LocalDateTime deletedDateTime; + + /** + * Gets the uin data. + * + * @return the uin data + */ + public byte[] getUinData() { + return uinData.clone(); + } + + /** + * Sets the uin data. + * + * @param uinData the new uin data + */ + public void setUinData(byte[] uinData) { + this.uinData = uinData.clone(); + } + + public String getUin() { + return uin; + } + + public void setUin(String uin) { + this.uin = uin; + } + +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/entity/UinHashSalt.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/entity/UinHashSalt.java new file mode 100644 index 000000000..71b30f4da --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/entity/UinHashSalt.java @@ -0,0 +1,47 @@ +package io.mosip.idrepository.remap.util.identity.entity; + +import java.time.LocalDateTime; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The Class UinHashSalt - Entity class for uin_hash_salt table. + * + * @author Prem Kumar. + */ +@Data +@Entity +@NoArgsConstructor +@Table(name = "uin_hash_salt", schema = "idrepo") +public class UinHashSalt { + + /** The Id value. */ + @Id + private int id; + + /** The salt value. */ + @Column(name = "salt") + private String salt; + + /** The value to hold created By. */ + @Column(name = "cr_by") + private String createdBy; + + /** The value to hold created DTimes. */ + @Column(name = "cr_dtimes") + private LocalDateTime createdDTimes; + + /** The value to hold updated By. */ + @Column(name = "upd_by") + private String updatedBy; + + /** The value to hold updated Time. */ + @Column(name = "upd_dtimes") + private LocalDateTime updatedDTimes; +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/entity/UinHistory.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/entity/UinHistory.java new file mode 100644 index 000000000..1384988ca --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/entity/UinHistory.java @@ -0,0 +1,111 @@ +package io.mosip.idrepository.remap.util.identity.entity; + +import java.time.LocalDateTime; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.Table; + +import org.hibernate.annotations.Type; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * The Class Uin -Entity class for uin table. + * + * @author Manoj SP + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "uin_h", schema = "idrepo") +@Entity +public class UinHistory { + + /** The uin ref id. */ + @Id + @Column(insertable = false, updatable = false, nullable = false) + private String uinRefId; + + /** The uin. */ + private String uin; + + private String uinHash; + + /** The uin data. */ + @Lob + @Type(type = "org.hibernate.type.BinaryType") + @Getter(AccessLevel.NONE) + @Setter(AccessLevel.NONE) + private byte[] uinData; + + /** The uin data hash. */ + private String uinDataHash; + + /** The reg id. */ + private String regId; + + private String bioRefId; + + /** The status code. */ + private String statusCode; + + private String langCode; + + /** The created by. */ + @Column(name = "cr_by") + private String createdBy; + + /** The created date time. */ + @Column(name = "cr_dtimes") + private LocalDateTime createdDateTime; + + /** The updated by. */ + @Column(name = "upd_by") + private String updatedBy; + + /** The updated date time. */ + @Column(name = "upd_dtimes") + private LocalDateTime updatedDateTime; + + /** The is deleted. */ + private Boolean isDeleted; + + /** The deleted date time. */ + @Column(name = "del_dtimes") + private LocalDateTime deletedDateTime; + + /** + * Gets the uin data. + * + * @return the uin data + */ + public byte[] getUinData() { + return uinData.clone(); + } + + /** + * Sets the uin data. + * + * @param uinData the new uin data + */ + public void setUinData(byte[] uinData) { + this.uinData = uinData.clone(); + } + + public String getUin() { + return uin; + } + + public void setUin(String uin) { + this.uin = uin; + } + +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/repository/UinHRepo.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/repository/UinHRepo.java new file mode 100644 index 000000000..425a3f96f --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/repository/UinHRepo.java @@ -0,0 +1,65 @@ +package io.mosip.idrepository.remap.util.identity.repository; + +import java.util.List; +import java.util.Set; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import io.mosip.idrepository.remap.util.identity.entity.Uin; +import io.mosip.idrepository.remap.util.identity.entity.UinHistory; + +/** + * The Interface UinRepo. + * + * @author Manoj SP + */ +public interface UinHRepo extends JpaRepository { + + /** + * Gets the uin by refId . + * + * @param regId the reg id + * @return the Uin + */ + @Query("select uinHash from Uin where regId = :regId") + String getUinHashByRid(@Param("regId") String regId); + + @Query("select uin from Uin where regId = :regId") + String getUinByRid(@Param("regId") String regId); + + /** + * Exists by reg id. + * + * @param regId the reg id + * @return true, if successful + */ + boolean existsByRegId(String regId); + + /** + * Gets the status by uin. + * + * @param uin the uin + * @return the status by uin + */ + @Query("select statusCode from Uin where uin = :uin") + String getStatusByUin(@Param("uin") String uin); + + /** + * Find by uin. + * + * @param uinHash the uin hash + * @return the uin + */ + List findByUinHashIn(Set uinHash); + + + /** + * Exists by uinHash. + * + * @param uinHash the uin Hash. + * @return true, if successful. + */ + boolean existsByUinHash(String uinHash); +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/repository/UinHashSaltRepo.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/repository/UinHashSaltRepo.java new file mode 100644 index 000000000..abc7e3c93 --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/repository/UinHashSaltRepo.java @@ -0,0 +1,26 @@ +package io.mosip.idrepository.remap.util.identity.repository; + +import org.springframework.cache.annotation.Cacheable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import io.mosip.idrepository.remap.util.identity.entity.UinHashSalt; + +/** + * The Interface UinHashSaltRepo. + * + * @author Prem Kumar + */ +public interface UinHashSaltRepo extends JpaRepository { + + /** + * The Query to retrieve salt by passing id as parameter. + * + * @param id the id + * @return String salt + */ + @Cacheable(cacheNames = "uin_hash_salt") + @Query("select salt from UinHashSalt where id = :id") + public String retrieveSaltById(@Param("id") int id); +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/repository/UinRepo.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/repository/UinRepo.java new file mode 100644 index 000000000..426a42b7a --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/identity/repository/UinRepo.java @@ -0,0 +1,64 @@ +package io.mosip.idrepository.remap.util.identity.repository; + +import java.util.List; +import java.util.Set; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import io.mosip.idrepository.remap.util.identity.entity.Uin; + +/** + * The Interface UinRepo. + * + * @author Manoj SP + */ +public interface UinRepo extends JpaRepository { + + /** + * Gets the uin by refId . + * + * @param regId the reg id + * @return the Uin + */ + @Query("select uinHash from Uin where regId = :regId") + String getUinHashByRid(@Param("regId") String regId); + + @Query("select uin from Uin where regId = :regId") + String getUinByRid(@Param("regId") String regId); + + /** + * Exists by reg id. + * + * @param regId the reg id + * @return true, if successful + */ + boolean existsByRegId(String regId); + + /** + * Gets the status by uin. + * + * @param uin the uin + * @return the status by uin + */ + @Query("select statusCode from Uin where uin = :uin") + String getStatusByUin(@Param("uin") String uin); + + /** + * Find by uin. + * + * @param uinHash the uin hash + * @return the uin + */ + List findByUinHashIn(Set uinHash); + + + /** + * Exists by uinHash. + * + * @param uinHash the uin Hash. + * @return true, if successful. + */ + boolean existsByUinHash(String uinHash); +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/service/RemapUtilService.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/service/RemapUtilService.java new file mode 100644 index 000000000..46507d3db --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/service/RemapUtilService.java @@ -0,0 +1,128 @@ +package io.mosip.idrepository.remap.util.service; + +import java.security.NoSuchAlgorithmException; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import javax.transaction.Transactional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import io.mosip.idrepository.remap.util.identity.entity.Uin; +import io.mosip.idrepository.remap.util.identity.repository.UinHashSaltRepo; +import io.mosip.idrepository.remap.util.identity.repository.UinRepo; +import io.mosip.idrepository.remap.util.vid.entity.Vid; +import io.mosip.idrepository.remap.util.vid.repository.VidRepo; +import io.mosip.idrepository.remap.util.vid.repository.VidUinHashSaltRepo; +import io.mosip.kernel.core.exception.BaseUncheckedException; +import io.mosip.kernel.core.util.CryptoUtil; +import io.mosip.kernel.core.util.DateUtils; +import io.mosip.kernel.core.util.HMACUtils2; + +/** + * @author Manoj SP + * + */ +@Service +@Transactional +public class RemapUtilService { + + public static final String SPLITTER = "_"; + + @Value("${mosip.idrepo.vid-type-to-remap}") + private String vidType; + + @Value("${mosip.idrepo.active-uin-status}") + private String activeUinStatus; + + @Value("${mosip.idrepo.uin-status-to-update}") + private String uinStatusToUpdate; + + @Value("${mosip.idrepo.updated-by}") + private String updatedBy; + + @Autowired + private Environment env; + + @Autowired + private UinHashSaltRepo uinHashSaltRepo; + + @Autowired + private VidUinHashSaltRepo vidHashSaltRepo; + + @Autowired + private UinRepo uinRepo; + + @Autowired + private VidRepo vidRepo; + + public Map> remap(String primaryUin, List uinToDeactivate) { + // get vid from vidrepo based on vid - uinhash + String primaryUinHash = generateHash(primaryUin, false); + Vid findByUinHash = vidRepo.findFirstByUinHash(primaryUinHash); + String encryptedUin = findByUinHash.getUin(); + Set uinHashList = uinToDeactivate.stream().map(uin -> generateHash(uin, false)) + .collect(Collectors.toSet()); + // update vid records of all vids mapped to uins which needs to be deactivated + List vidObjectList = vidRepo.findByUinHashIn(uinHashList); + for (Vid vid : vidObjectList) { + vid.setUinHash(primaryUinHash); + vid.setUin(encryptedUin); + vid.setUpdatedDTimes(DateUtils.getUTCCurrentDateTime()); + vid.setUpdatedBy(updatedBy); + vid.setVidTypeCode(vidType); + } + vidRepo.saveAll(vidObjectList); + deactivateUin(uinToDeactivate); + return Map.of("uinsDeactivated", uinToDeactivate, "vidsRemapped", + vidObjectList.stream().map(Vid::getVid).collect(Collectors.toList())); + } + + private void deactivateUin(List uinToDeactivate) { + Map uinHashMap = uinToDeactivate.stream().distinct() + .collect(Collectors.toMap(uin -> generateHash(uin, true), uin -> uin)); + List uinObjectList = uinRepo.findByUinHashIn(uinHashMap.keySet()); + for(Uin uinObj : uinObjectList) { + if (!uinObj.getStatusCode().contentEquals(activeUinStatus)) { + throw new BaseUncheckedException("", "Uin is already deactivated - " + uinHashMap.get(uinObj.getUinHash())); + } + uinObj.setStatusCode(uinStatusToUpdate); + uinObj.setUpdatedDateTime(DateUtils.getUTCCurrentDateTime()); + uinObj.setUpdatedBy(updatedBy); + } + uinRepo.saveAll(uinObjectList); + } + + private String generateHash(String uin, boolean isUin) { + try { + int saltId = this.getSaltKeyForId(uin); + String hashSalt = isUin ? uinHashSaltRepo.retrieveSaltById(saltId) : vidHashSaltRepo.retrieveSaltById(saltId); + return String.valueOf(saltId) + SPLITTER + + this.hashwithSalt(uin.getBytes(), isUin ? hashSalt.getBytes() : CryptoUtil.decodePlainBase64(hashSalt)); + } catch (NoSuchAlgorithmException e) { + throw new BaseUncheckedException("", "Failed to generate Hash for uin - " + uin, e); + } + } + + public int getSaltKeyForId(String id) { + Integer saltKeyLength = env.getProperty("mosip.identity.salt.key.length", Integer.class, 3); + return RemapUtilService.getIdvidModulo(id, saltKeyLength); + } + + public static final int getIdvidModulo(String idvid, int substrigLen) { + Assert.isTrue(substrigLen > 0, "divisor should be positive integer"); + int length = idvid.length(); + return length <= substrigLen ? Integer.parseInt(idvid) + : Integer.parseInt(idvid.substring(length - substrigLen)); + } + + public String hashwithSalt(final byte[] data, final byte[] salt) throws NoSuchAlgorithmException { + return HMACUtils2.digestAsPlainTextWithSalt(data, salt); + } +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/entity/Vid.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/entity/Vid.java new file mode 100644 index 000000000..586deb665 --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/entity/Vid.java @@ -0,0 +1,80 @@ +package io.mosip.idrepository.remap.util.vid.entity; + +import java.time.LocalDateTime; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The Entity for Vid. + * + * @author Prem Kumar + * + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "vid", schema = "idmap") +@Entity +public class Vid { + + /** The Id value */ + @Id + private String id; + + /** The vid value */ + private String vid; + + /** The uin Hash value */ + @Column(name = "uin_hash") + private String uinHash; + + /** The uin value */ + private String uin; + + /** The value to hold vid Type Code */ + @Column(name = "vidtyp_code") + private String vidTypeCode; + + /** The value to hold generated DTimes */ + @Column(name = "generated_dtimes") + private LocalDateTime generatedDTimes; + + /** The value to hold expiry DTimes */ + @Column(name = "expiry_dtimes") + private LocalDateTime expiryDTimes; + + /** The value to hold status Code */ + @Column(name = "status_code") + private String statusCode; + + /** The value to hold created By */ + @Column(name = "cr_by") + private String createdBy; + + /** The value to hold created DTimes */ + @Column(name = "cr_dtimes") + private LocalDateTime createdDTimes; + + /** The value to hold updated By */ + @Column(name = "upd_by", nullable = true) + private String updatedBy; + + /** The value to hold updated Time */ + @Column(name = "upd_dtimes", nullable = true) + private LocalDateTime updatedDTimes; + + @Column(name = "is_deleted", nullable = true) + private boolean isDeleted; + + /** The value to hold deleted DTimes */ + @Column(name = "del_dtimes", nullable = true) + private LocalDateTime deletedDTimes; + +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/entity/VidUinHashSalt.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/entity/VidUinHashSalt.java new file mode 100644 index 000000000..1915558b2 --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/entity/VidUinHashSalt.java @@ -0,0 +1,47 @@ +package io.mosip.idrepository.remap.util.vid.entity; + +import java.time.LocalDateTime; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The Class UinHashSalt - Entity class for uin_hash_salt table. + * + * @author Prem Kumar. + */ +@Data +@Entity +@NoArgsConstructor +@Table(name = "uin_hash_salt", schema = "idmap") +public class VidUinHashSalt { + + /** The Id value. */ + @Id + private int id; + + /** The salt value. */ + @Column(name = "salt") + private String salt; + + /** The value to hold created By. */ + @Column(name = "cr_by") + private String createdBy; + + /** The value to hold created DTimes. */ + @Column(name = "cr_dtimes") + private LocalDateTime createdDTimes; + + /** The value to hold updated By. */ + @Column(name = "upd_by") + private String updatedBy; + + /** The value to hold updated Time. */ + @Column(name = "upd_dtimes") + private LocalDateTime updatedDTimes; +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/repository/VidRepo.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/repository/VidRepo.java new file mode 100644 index 000000000..f7d69114c --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/repository/VidRepo.java @@ -0,0 +1,56 @@ +package io.mosip.idrepository.remap.util.vid.repository; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Set; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import io.mosip.idrepository.remap.util.vid.entity.Vid; + +/** + * The Repository for Vid Entity. + * + * @author Manoj SP + * @author Prem Kumar + */ +@Repository +public interface VidRepo extends JpaRepository { + + /** + * This Method is used to retrieve Vid Object. + * + * @param vid the vid + * @return Vid Object + */ + Vid findByVid(String vid); + + /** + * The Query will retrieve List of vid based on the conditions provided. + * + * @param uinHash the uin hash + * @param statusCode the status code + * @param vidTypeCode the vid type code + * @param currentTime the current time + * @return the list + */ + List findByUinHashAndStatusCodeAndVidTypeCodeAndExpiryDTimesAfter(String uinHash, String statusCode, String vidTypeCode, LocalDateTime currentTime); + + /** + * The Query to retrieve Uin by passing vid as parameter. + * + * @param vid the vid + * @return String Uin + */ + @Query("select uin from Vid where vid = :vid") + public String retrieveUinByVid(@Param("vid") String vid); + + List findByUinHashAndStatusCodeAndExpiryDTimesAfter(String uinHash, String statusCode, LocalDateTime currentTime); + + List findByUinHashIn(Set uinHashList); + + Vid findFirstByUinHash(String uinHash); +} diff --git a/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/repository/VidUinHashSaltRepo.java b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/repository/VidUinHashSaltRepo.java new file mode 100644 index 000000000..708b559b0 --- /dev/null +++ b/deployment/sandbox-v2/utils/id-repository-uin-remap-util/src/main/java/io/mosip/idrepository/remap/util/vid/repository/VidUinHashSaltRepo.java @@ -0,0 +1,26 @@ +package io.mosip.idrepository.remap.util.vid.repository; + +import org.springframework.cache.annotation.Cacheable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import io.mosip.idrepository.remap.util.vid.entity.VidUinHashSalt; + +/** + * The Interface UinHashSaltRepo. + * + * @author Prem Kumar + */ +public interface VidUinHashSaltRepo extends JpaRepository { + + /** + * The Query to retrieve salt by passing id as parameter. + * + * @param id the id + * @return String salt + */ + @Cacheable(cacheNames = "uin_hash_salt") + @Query("select salt from VidUinHashSalt where id = :id") + public String retrieveSaltById(@Param("id") int id); +}