-
Notifications
You must be signed in to change notification settings - Fork 575
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
HV-1970 Add Korean specific RRN annotation #1338
Conversation
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.
Thanks for your pull request.
This post on adding new constraints may be interesting to you, if you haven't seen it before: https://in.relation.to/2018/01/04/adding-new-constraint-to-engine/ . See the annotation processor and documentation steps in particular.
Also, maybe you could update the ValidationMessages_ko.properties
file with the new message as well?
public class KorRRNValidator implements ConstraintValidator<KorRRN, CharSequence> { | ||
|
||
private static final Pattern KOR_RRN_REGEX = Pattern.compile( | ||
"\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])-[1234]\\d{6}$" ); |
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.
Do you think it is worth to check the check digit for the older numbers?
c, the 13th digit, is a check digit, used to verify that the number has been transcribed correctly. It is generated from the rest of the digits using the following algorithm (digits lettered a through m in order):
m = [11 − {(2a + 3b + 4c + 5d + 6e + 7f + 8g + 9h + 2i + 3j + 4k + 5l) mod 11}] mod 10
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.
What is meaning "older number"?
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.
From what I understand, for RRNs issued prior to October 2020 the last digit in the number was a check-digit. After that date, it became a random number. So I was asking if it would make sense to validate the check-digit for numbers issued prior to October 2020.
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.
As far as I know, RRNs are still using check digits after October 2020.
Let's say "RRN" is "ABCDEF-GHIJKLM", then Since October 2020, 'HIJKL' has been changed to a randomized order, but check-digits(M) are valid
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.
I checked and the law is ambiguous.
See Government homepage 2020.05
See Government homepage 2020.05
So, I'll check with the government tomorrow.
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.
Thank you! that would be nice.
Also as an idea: we could try adding an attribute to the constraint annotation:
public @interface KorRRN {
// ...
boolean validateCheckDigit() default true;
}
to make the validation optional. Or take it a step further and:
public @interface KorRRN {
//...
ValidateCheckDigit validateCheckDigit() default ValidateCheckDigit.ALWAYS;
enum ValidateCheckDigit {
NEVER,
ALWAYS,
BEFORE_OCTOBER_2020_ONLY
}
}
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.
I called the Korean goverment and they said you're right. 😂 This seems like a good idea. So I Updated KorRRN to include "validateCheckDigit"attribute and i added a few test cases.
engine/src/main/java/org/hibernate/validator/constraints/kor/KorRRN.java
Outdated
Show resolved
Hide resolved
Thanks for your pull request! This pull request appears to follow the contribution rules. › This message was automatically generated. |
Co-authored-by: Marko Bekhta <[email protected]>
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.
Nice progress! I've added a few comments inline.
.../main/java/org/hibernate/validator/internal/constraintvalidators/hv/kor/KorRRNValidator.java
Show resolved
Hide resolved
...a/org/hibernate/validator/test/internal/constraintvalidators/hv/kor/KorRRNValidatorTest.java
Outdated
Show resolved
Hide resolved
...a/org/hibernate/validator/test/internal/constraintvalidators/hv/kor/KorRRNValidatorTest.java
Outdated
Show resolved
Hide resolved
…refactoring test codes
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.
Hey,
Thanks for your work! I think we are nearly there. There are a few inline comments, mostly about the style to align things with the existing code. And also, we'd want to add this new constraint to the documentation here:
hibernate-validator/documentation/src/main/asciidoc/ch02.asciidoc
Lines 759 to 760 in 729cd01
`@NIP`:: Checks that the annotated character sequence represents a Polish VAT identification number (https://pl.wikipedia.org/wiki/NIP[NIP]) |
Jira-(HV-1970)
Hai I tried to add Korean specific @rrn annotation.
I added annotation, validator, testcases, messages, etc.