-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOSIP-23551: Added validators for DocType and DocCat code in valid do…
…cument entity Signed-off-by: Balaji <[email protected]>
- Loading branch information
1 parent
edd8942
commit 71db745
Showing
9 changed files
with
170 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
admin/admin-service/src/main/java/io/mosip/admin/validator/DocCatCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
} |
50 changes: 50 additions & 0 deletions
50
admin/admin-service/src/main/java/io/mosip/admin/validator/DocCatCodeValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
@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; | ||
} | ||
|
||
|
||
} |
27 changes: 27 additions & 0 deletions
27
admin/admin-service/src/main/java/io/mosip/admin/validator/DocTypeCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
admin/admin-service/src/main/java/io/mosip/admin/validator/DocTypeCodeValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
@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; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters