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 e5270e83177..b8a972a55a0 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,8 @@ import javax.persistence.Table; import io.mosip.admin.bulkdataupload.entity.id.ValidDocumentID; +import io.mosip.admin.validator.DocCatCode; +import io.mosip.admin.validator.DocTypeCode; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; @@ -43,12 +45,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 = "docType is Invalid") private String docTypeCode; + @Id + @Column(name = "doccat_code", nullable = false, length = 36) + @DocCatCode(message = "docCategory is Invalid") 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/validator/DocCatCode.java b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocCatCode.java new file mode 100644 index 00000000000..1da5ee9c642 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocCatCode.java @@ -0,0 +1,23 @@ +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; + +@Documented +@Constraint(validatedBy = DocCatCodeValidator.class) +@Target({ ElementType.FIELD, ElementType.TYPE_USE, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface DocCatCode { + + String message() default "docCategory is Invalid"; + + 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..84d4e120b4f --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocCatCodeValidator.java @@ -0,0 +1,50 @@ +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 { + + private List docCatCode; + + @Autowired + private DocumentCategoryRepository documentCategoryRepository; + + @Override + public void initialize(DocCatCode constraintAnnotation) { + if(documentCategoryRepository == 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; + } + docCatCode = documentCategoryRepository.findAllByIsDeletedFalseOrIsDeletedIsNull(); + } + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + + if(documentCategoryRepository == 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 docCatCode.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..47846993203 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocTypeCode.java @@ -0,0 +1,27 @@ +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; + + + + +@Documented +@Constraint(validatedBy = DocTypeCodeValidator.class) +@Target({ ElementType.FIELD, ElementType.TYPE_USE, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface DocTypeCode { + + String message() default "docType is Invalid"; + + 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..84b7b110da1 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/validator/DocTypeCodeValidator.java @@ -0,0 +1,53 @@ +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 { + + private List docTypeCode; + + @Autowired + DocumentTypeRepository documentTypeRepository; + + + @Override + public void initialize(DocTypeCode constraintAnnotation) { + if(documentTypeRepository == 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; + } + docTypeCode = documentTypeRepository.findAllByIsDeletedFalseOrIsDeletedIsNull(); + } + + + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + if(documentTypeRepository == 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 docTypeCode.contains(value); + } + return false; + } + + +} 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 c9e8d9fb983..06443cd753f 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 @@ -113,7 +113,7 @@ public void setUp() throws Exception { @Test @WithUserDetails(value = "zonal-admin") public void t002lostRidTest() throws Exception { - String str = "{\r\n \"id\": null,\r\n \"version\": null,\r\n \"responsetime\": \"2019-12-02T09:45:24.512Z\",\r\n \"metadata\": null,\r\n \"response\": [{\"registrationId\":\"1234\",\"registrationDate\":\"2021-12-14 16:29:13,436\"}],\r\n \"errors\": []\r\n}"; + String str = "{\r\n \"id\": null,\r\n \"version\": null,\r\n \"responsetime\": \"2019-12-02T09:45:24.512Z\",\r\n \"metadata\": null,\r\n \"response\": [{\"registrationId\":\"1234\",\"registrationDate\":\"2022-09-14 16:29:13,436\"}],\r\n \"errors\": []\r\n}"; searchInfoReq.getRequest().setSort(new ArrayList()); mockRestServiceServer.expect(requestTo(lstRidUrl)) @@ -122,7 +122,7 @@ public void t002lostRidTest() 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 2d28fc46708..14d02a6de45 100644 --- a/admin/admin-service/src/test/resources/application-test.properties +++ b/admin/admin-service/src/test/resources/application-test.properties @@ -474,4 +474,5 @@ mosip.admin.applicant-details.exposed-identity-fields=dob,applicantPhoto 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 \ No newline at end of file +PACKET_MANAGER_SEARCHFIELDS=https://api-internal.dev.mosip.net/commons/v1/packetmanager/searchFields +mosip.registration.processor.lostrid.max-registration-date-filter-interval=30