-
Notifications
You must be signed in to change notification settings - Fork 140
[MOSIP-23551] Added validators for doctype and docCat Fileds in Valid document #1180
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,15 +2,24 @@ | |
|
|
||
| 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 +30,36 @@ | |
| @Configuration | ||
| public class CommonConfig { | ||
|
|
||
| @Autowired | ||
| private DocumentCategoryRepository documentCategoryRepository; | ||
|
|
||
| @Autowired | ||
| private DocumentTypeRepository documentTypeRepository; | ||
|
|
||
| private List<String> docCatCodes; | ||
|
|
||
| private List<String> docTypeCodes; | ||
|
|
||
| private List<String> getDocCatCodes(){ | ||
| if(docCatCodes.isEmpty()) { | ||
| docCatCodes = documentCategoryRepository.findAllByIsDeletedFalseOrIsDeletedIsNull(); | ||
| } | ||
| return docCatCodes; | ||
| } | ||
|
|
||
| private List<String> 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 +92,16 @@ public Properties packetProperties() { | |
| } catch (IOException e) { } | ||
| return properties; | ||
| } | ||
|
|
||
| @Bean("DocCatCodes") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let the bean name start with lowercase |
||
| @Scope(value = "prototype") | ||
| public List<String> docCatCodes(){ | ||
| return getDocCatCodes(); | ||
| } | ||
|
|
||
| @Bean("DocTypeCodes") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let the bean name start with lowercase |
||
| @Scope(value = "prototype") | ||
| public List<String> docTypeCodes(){ | ||
| return getDocTypeCodes(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<? extends Payload>[] payload() default {}; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<DocCatCode, String> { | ||
|
|
||
| @Autowired | ||
| private List<String> 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; | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<? extends Payload>[] payload() default {}; | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<DocTypeCode, String> { | ||
|
|
||
| @Autowired | ||
| private List<String> 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; | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a comment to specify the value unit? and also what codes are cleaned. |
||
| 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -307,4 +307,4 @@ public void testBuildSearchFieldsRequestDtoWithNullRid() { | |
| assertFalse(fieldDtos.getBypassCache()); | ||
| } | ||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be error message or error code?