Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOSIP-23551: Added validators for DocType and DocCat code in valid document entity #937

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
balaji-alluru marked this conversation as resolved.
Show resolved Hide resolved
private String docTypeCode;

@Id
@Column(name = "doccat_code", nullable = false, length = 36)
@DocCatCode(message = "docCategory is Invalid")
balaji-alluru marked this conversation as resolved.
Show resolved Hide resolved
private String docCategoryCode;

@ManyToOne(fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ public interface DocumentCategoryRepository extends BaseRepository<DocumentCateg

@Query("FROM DocumentCategory WHERE code =?1 AND langCode =?2 AND (isDeleted is null OR isDeleted = false)")
DocumentCategory findByCodeAndLangCode(String code, String langCode);

@Query(value = "select dt.code from master.doc_category dt where (dt.is_deleted = false or dt.is_deleted is null) AND dt.is_active = true", nativeQuery = true)
List<String> findAllByIsDeletedFalseOrIsDeletedIsNull();
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ public interface DocumentTypeRepository extends BaseRepository<DocumentType, Cod
*/
@Query("FROM DocumentType WHERE langCode =?1 AND (isDeleted is null OR isDeleted = false) AND isActive = true")
List<DocumentType> 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<String> findAllByIsDeletedFalseOrIsDeletedIsNull();
}
Original file line number Diff line number Diff line change
@@ -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";
balaji-alluru marked this conversation as resolved.
Show resolved Hide resolved

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -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<DocCatCode, String> {

private List<String> docCatCode;
balaji-alluru marked this conversation as resolved.
Show resolved Hide resolved

@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);
balaji-alluru marked this conversation as resolved.
Show resolved Hide resolved
}
return false;
}


}
Original file line number Diff line number Diff line change
@@ -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";
balaji-alluru marked this conversation as resolved.
Show resolved Hide resolved

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};

}
Original file line number Diff line number Diff line change
@@ -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<DocTypeCode, String> {

private List<String> docTypeCode;
balaji-alluru marked this conversation as resolved.
Show resolved Hide resolved

@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);
balaji-alluru marked this conversation as resolved.
Show resolved Hide resolved
}
return false;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void setUp() throws Exception {
@Test
@WithUserDetails(value = "zonal-admin")
public void t002lostRidTest() throws Exception {
balaji-alluru marked this conversation as resolved.
Show resolved Hide resolved
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<SortInfo>());

mockRestServiceServer.expect(requestTo(lstRidUrl))
Expand All @@ -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");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
PACKET_MANAGER_SEARCHFIELDS=https://api-internal.dev.mosip.net/commons/v1/packetmanager/searchFields
mosip.registration.processor.lostrid.max-registration-date-filter-interval=30