forked from mosip/esignet-signup
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: pr <[email protected]> Signed-off-by: Sreang Rathanak <[email protected]>
- Loading branch information
1 parent
2533e97
commit 6a19e9a
Showing
7 changed files
with
122 additions
and
37 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
25 changes: 25 additions & 0 deletions
25
signup-service/src/main/java/io/mosip/signup/validator/LanguageValue.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,25 @@ | ||
package io.mosip.signup.validator; | ||
|
||
import io.mosip.signup.util.ErrorConstants; | ||
|
||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.TYPE_USE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Target({FIELD, TYPE_USE}) | ||
@Retention(RUNTIME) | ||
@Constraint(validatedBy = LanguageValueValidator.class) | ||
@Documented | ||
public @interface LanguageValue { | ||
String message() default ErrorConstants.INVALID_FULLNAME; | ||
Class<?>[] groups() default { }; | ||
Class<? extends Payload>[] payload() default { }; | ||
String language() default "khm"; | ||
String valuePatternKey(); | ||
} |
30 changes: 30 additions & 0 deletions
30
signup-service/src/main/java/io/mosip/signup/validator/LanguageValueValidator.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,30 @@ | ||
package io.mosip.signup.validator; | ||
|
||
import io.mosip.signup.dto.LanguageTaggedValue; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
|
||
public class LanguageValueValidator implements ConstraintValidator<LanguageValue, LanguageTaggedValue> { | ||
|
||
private String valuePattern; | ||
private String language; | ||
|
||
@Autowired | ||
private Environment environment; | ||
|
||
@Override | ||
public void initialize(LanguageValue value) { | ||
this.valuePattern = environment.getProperty(value.valuePatternKey()); | ||
this.language = value.language(); | ||
} | ||
|
||
@Override | ||
public boolean isValid(LanguageTaggedValue value, ConstraintValidatorContext constraintValidatorContext) { | ||
if(value == null) | ||
return false; | ||
return value.getLanguage().equals(this.language) && value.getValue().matches(valuePattern); | ||
} | ||
} |
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
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