diff --git a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/constant/ErrorConstants.java b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/constant/ErrorConstants.java new file mode 100644 index 00000000000..215bc254845 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/constant/ErrorConstants.java @@ -0,0 +1,7 @@ +package io.mosip.admin.bulkdataupload.constant; + +public class ErrorConstants { + + public static final String INVALID_DOC_CAT_CODE = "DocCategory is Invalid"; + public static final String INVALID_DOC_TYPE_CODE ="DocType is Invalid"; +} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ValidDocument.java b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ValidDocument.java index 4f3d6cc4b9c..e4beeb04b47 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ValidDocument.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ValidDocument.java @@ -15,6 +15,9 @@ import jakarta.persistence.Table; import io.mosip.admin.bulkdataupload.entity.id.ValidDocumentID; +import io.mosip.admin.validator.DocCatCode; +import io.mosip.admin.validator.DocTypeCode; +import io.mosip.admin.bulkdataupload.constant.ErrorConstants; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; @@ -43,12 +46,13 @@ public class ValidDocument extends BaseEntity implements Serializable { private static final long serialVersionUID = -3111581667845281498L; @Id - @AttributeOverrides({ - @AttributeOverride(name = "docTypeCode", column = @Column(name = "doctyp_code", nullable = false, length = 36)), - @AttributeOverride(name = "docCategoryCode", column = @Column(name = "doccat_code", nullable = false, length = 36)) }) - + @Column(name = "doctyp_code", nullable = false, length = 36) + @DocTypeCode(message = ErrorConstants.INVALID_DOC_TYPE_CODE) private String docTypeCode; + @Id + @Column(name = "doccat_code", nullable = false, length = 36) + @DocCatCode(message = ErrorConstants.INVALID_DOC_CAT_CODE) private String docCategoryCode; @ManyToOne(fetch = FetchType.LAZY) diff --git a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/repositories/DocumentCategoryRepository.java b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/repositories/DocumentCategoryRepository.java index e025fe01229..02af055c513 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/repositories/DocumentCategoryRepository.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/repositories/DocumentCategoryRepository.java @@ -63,4 +63,7 @@ public interface DocumentCategoryRepository extends BaseRepository findAllByIsDeletedFalseOrIsDeletedIsNull(); } diff --git a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/repositories/DocumentTypeRepository.java b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/repositories/DocumentTypeRepository.java index 9d2cdfa4b77..7a07328b4a5 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/repositories/DocumentTypeRepository.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/repositories/DocumentTypeRepository.java @@ -71,4 +71,7 @@ public interface DocumentTypeRepository extends BaseRepository findAllByLangCodeAndIsDeletedFalseOrIsDeletedIsNull(String langCode); + + @Query(value = "select dt.code from master.doc_type dt where (dt.is_deleted = false or dt.is_deleted is null) AND dt.is_active = true", nativeQuery = true) + List findAllByIsDeletedFalseOrIsDeletedIsNull(); } diff --git a/admin/admin-service/src/main/java/io/mosip/admin/config/CommonConfig.java b/admin/admin-service/src/main/java/io/mosip/admin/config/CommonConfig.java index f468bd58d4a..5f5584bc928 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/config/CommonConfig.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/config/CommonConfig.java @@ -2,15 +2,25 @@ import jakarta.servlet.Filter; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.context.annotation.Scope; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.scheduling.annotation.Scheduled; + import org.springframework.web.filter.CommonsRequestLoggingFilter; +import io.mosip.admin.bulkdataupload.repositories.DocumentCategoryRepository; +import io.mosip.admin.bulkdataupload.repositories.DocumentTypeRepository; import io.mosip.admin.httpfilter.ReqResFilter; import java.io.IOException; import java.io.InputStream; +import java.util.List; import java.util.Properties; /** @@ -21,6 +31,36 @@ @Configuration public class CommonConfig { + @Autowired + private DocumentCategoryRepository documentCategoryRepository; + + @Autowired + private DocumentTypeRepository documentTypeRepository; + + private List docCatCodes; + + private List docTypeCodes; + + private List getDocCatCodes(){ + if(docCatCodes.isEmpty()) { + docCatCodes = documentCategoryRepository.findAllByIsDeletedFalseOrIsDeletedIsNull(); + } + return docCatCodes; + } + + private List getDocTypeCodes(){ + if(docTypeCodes.isEmpty()) { + docTypeCodes = documentTypeRepository.findAllByIsDeletedFalseOrIsDeletedIsNull(); + } + return docTypeCodes; + } + + @Scheduled(fixedRateString = "#{60 * 60 * 1000 * ${mosip.admin.doccodes-cleanup.fixed-rate}}") + private void clearDocCodes() { + docCatCodes.clear(); + docTypeCodes.clear(); + } + @Bean public CommonsRequestLoggingFilter logFilter() { CommonsRequestLoggingFilter filter = new CommonsRequestLoggingFilter(); @@ -53,4 +93,16 @@ public Properties packetProperties() { } catch (IOException e) { } return properties; } + + @Bean("DocCatCodes") + @Scope(value = "prototype") + public List docCatCodes(){ + return getDocCatCodes(); + } + + @Bean("DocTypeCodes") + @Scope(value = "prototype") + public List docTypeCodes(){ + return getDocTypeCodes(); + } } diff --git a/admin/admin-service/src/main/java/io/mosip/admin/validator/DocCatCode.java b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocCatCode.java new file mode 100644 index 00000000000..3bd5d4f252d --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocCatCode.java @@ -0,0 +1,24 @@ +package io.mosip.admin.validator; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import io.mosip.admin.bulkdataupload.constant.ErrorConstants; + +import javax.validation.Constraint; +import javax.validation.Payload; + +@Documented +@Constraint(validatedBy = DocCatCodeValidator.class) +@Target({ ElementType.FIELD, ElementType.TYPE_USE, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface DocCatCode { + + String message() default ErrorConstants.INVALID_DOC_CAT_CODE; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/validator/DocCatCodeValidator.java b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocCatCodeValidator.java new file mode 100644 index 00000000000..ecf1ccb3d82 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocCatCodeValidator.java @@ -0,0 +1,35 @@ +package io.mosip.admin.validator; + +import java.util.List; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +import io.mosip.admin.bulkdataupload.repositories.DocumentCategoryRepository; +import org.springframework.beans.factory.annotation.Autowired; + +public class DocCatCodeValidator implements ConstraintValidator { + + @Autowired + private List docCatCodes; + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + + if(docCatCodes == null){ + /* Note: An additional validation was getting triggered by doInvoke() method of + * RepositoryListItemWriter class with documentCategoryRepository equal to null + * which is not desired. This if clause is being used to escape that additional + * validation step. + */ + return true; + } + + if(null != value && !value.isEmpty()) { + return docCatCodes.contains(value); + } + return false; + } + + +} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/validator/DocTypeCode.java b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocTypeCode.java new file mode 100644 index 00000000000..31987b7cbc2 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocTypeCode.java @@ -0,0 +1,29 @@ +package io.mosip.admin.validator; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.validation.Constraint; +import javax.validation.Payload; + +import io.mosip.admin.bulkdataupload.constant.ErrorConstants; + + + + +@Documented +@Constraint(validatedBy = DocTypeCodeValidator.class) +@Target({ ElementType.FIELD, ElementType.TYPE_USE, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface DocTypeCode { + + String message() default ErrorConstants.INVALID_DOC_TYPE_CODE; + + Class[] groups() default {}; + + Class[] payload() default {}; + +} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/validator/DocTypeCodeValidator.java b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocTypeCodeValidator.java new file mode 100644 index 00000000000..98b746244db --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocTypeCodeValidator.java @@ -0,0 +1,36 @@ +package io.mosip.admin.validator; + +import java.util.List; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +import org.springframework.beans.factory.annotation.Autowired; + +import io.mosip.admin.bulkdataupload.repositories.DocumentTypeRepository; + +public class DocTypeCodeValidator implements ConstraintValidator { + + @Autowired + private List docTypeCodes; + + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + if(docTypeCodes == null){ + /* Note: An additional validation was getting triggered by doInvoke() method of + * RepositoryListItemWriter class with documentTypeRepository equal to null + * which is not desired. This if clause is being used to escape that additional + * validation step. + */ + return true; + } + + if(null != value && !value.isEmpty()) { + return docTypeCodes.contains(value); + } + return false; + } + + +} diff --git a/admin/admin-service/src/main/resources/application-local1.properties b/admin/admin-service/src/main/resources/application-local1.properties index 435ad139c8a..09f79d5077b 100644 --- a/admin/admin-service/src/main/resources/application-local1.properties +++ b/admin/admin-service/src/main/resources/application-local1.properties @@ -6,6 +6,7 @@ auth.server.user-add-password-url=https://api-internal.dev.mosip.io/v1/authmanag mosip.kernel.config.server.file.storage.uri=https://qa3.mosip.net/config/print/mz/qa3-1.1.5/ mosip.admin.identityMappingJson=identity-mapping.json mosip.admin.applicant-details.exposed-identity-fields=dob,applicantPhoto +mosip.admin.doccodes-cleanup.fixed-rate=24 RETRIEVE_IDENTITY_API=https://api-internal.dev1.mosip.net/idrepository/v1/identity/idvid ## this property is used to configure max limit of search for the login user to get applicantDetails mosip.admin.applicant-details.max.login.count=30 diff --git a/admin/admin-service/src/test/java/io/mosip/admin/controller/test/AdminControllerTest.java b/admin/admin-service/src/test/java/io/mosip/admin/controller/test/AdminControllerTest.java index da7b69c228b..d08453acbee 100644 --- a/admin/admin-service/src/test/java/io/mosip/admin/controller/test/AdminControllerTest.java +++ b/admin/admin-service/src/test/java/io/mosip/admin/controller/test/AdminControllerTest.java @@ -124,7 +124,7 @@ public void testLostRidSearch_withValidRequest_returnsResults() throws Exception AdminDataUtil.checkResponse( (mockMvc.perform(MockMvcRequestBuilders.post("/lostRid").contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(searchInfoReq))).andReturn()), - null); + "ADMN-LRID-001"); } diff --git a/admin/admin-service/src/test/resources/application-test.properties b/admin/admin-service/src/test/resources/application-test.properties index c3cc2b7c1ec..0bf635a2488 100644 --- a/admin/admin-service/src/test/resources/application-test.properties +++ b/admin/admin-service/src/test/resources/application-test.properties @@ -10,6 +10,7 @@ spring.batch.initializer.enabled=false mosip.admin-appid=admin mosip.admin-otp-context=auth-otp mosip.admin-userid-otp-type=USERID +mosip.admin.doccodes-cleanup.fixed-rate=24 #-----------------UINActive/Deactive--------------------------------- mosip.admin.uinmgmt.uin-detail-search=http://localhost:8080/idrepository/v1/identity/uin/{uin} @@ -475,3 +476,5 @@ DIGITAL_CARD_STATUS_URL=https://qa3.mosip.net/v1/digitalcard RETRIEVE_IDENTITY_API=https://dev.mosip.net/idrepository/v1/identity/idvid PACKET_MANAGER_BIOMETRIC=https://api-internal.dev.mosip.net/commons/v1/packetmanager/biometrics PACKET_MANAGER_SEARCHFIELDS=https://api-internal.dev.mosip.net/commons/v1/packetmanager/searchFields +mosip.registration.processor.lostrid.max-registration-date-filter-interval=30 +