Skip to content

Commit 30abca4

Browse files
committed
Initial commit: v0.1.0 of levitas-validators
0 parents  commit 30abca4

38 files changed

Lines changed: 4446 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
name: Build & Test (Java ${{ matrix.java }})
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
java: [ '17', '21' ]
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Set up JDK ${{ matrix.java }}
23+
uses: actions/setup-java@v4
24+
with:
25+
java-version: ${{ matrix.java }}
26+
distribution: temurin
27+
cache: maven
28+
29+
- name: Build and verify (includes tests + JaCoCo coverage check)
30+
run: mvn -B verify
31+
32+
- name: Upload JaCoCo coverage report
33+
if: matrix.java == '17'
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: jacoco-report
37+
path: target/site/jacoco/
38+
retention-days: 14

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Maven
2+
target/
3+
pom.xml.tag
4+
pom.xml.releaseBackup
5+
pom.xml.versionsBackup
6+
pom.xml.next
7+
release.properties
8+
dependency-reduced-pom.xml
9+
buildNumber.properties
10+
.mvn/timing.properties
11+
.mvn/wrapper/maven-wrapper.jar
12+
13+
# Compiled class files
14+
*.class
15+
16+
# Log files
17+
*.log
18+
19+
# IDE — IntelliJ IDEA
20+
.idea/
21+
*.iml
22+
*.iws
23+
*.ipr
24+
out/
25+
26+
# IDE — Eclipse
27+
.classpath
28+
.project
29+
.settings/
30+
bin/
31+
32+
# IDE — VS Code
33+
.vscode/
34+
*.code-workspace
35+
36+
# OS
37+
.DS_Store
38+
Thumbs.db
39+
Desktop.ini
40+
41+
# JaCoCo
42+
*.exec

CHANGELOG.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.1.0] — 2024-04-13
11+
12+
### Added
13+
14+
- **GSTIN validator** (`GstinValidator`) — format validation, base-36 checksum verification,
15+
state code extraction, PAN extraction, full parse into `GstinInfo`
16+
- **StateCode enum** — all 40 Indian state/UT GST codes with display names and
17+
`fromCode(String)` lookup
18+
- **EntityType enum** — REGULAR entity type for GSTIN registration count character
19+
- **PAN validator** (`PanValidator`) — format validation, entity type extraction
20+
(individual, company, HUF, firm, trust, government, AOP, BOI, local authority,
21+
artificial juridical person)
22+
- **PanEntityType enum** — all 10 IT department entity type codes with descriptions
23+
- **HSN validator** (`HsnValidator`) — 2/4/6/8 digit validation, turnover-based
24+
minimum digit requirements (4 digits ≤ ₹5 crore, 6 digits > ₹5 crore),
25+
export/import 8-digit check
26+
- **IFSC validator** (`IfscValidator`) — format validation, bank code extraction,
27+
bank name lookup, branch code extraction
28+
- **BankRegistry** — 46 major Indian banks bundled as JSON resource, loaded via Jackson
29+
- **UPI VPA validator** (`VpaValidator`) — format validation, username/handle extraction,
30+
PSP name lookup
31+
- **PspRegistry** — 36 known UPI PSP handles bundled as JSON resource
32+
- **Aadhaar validator** (`AadhaarValidator`) — Verhoeff checksum validation, format check,
33+
space/hyphen separator support
34+
- **AadhaarMasker** — DPDP-compliant masking (`XXXX-XXXX-NNNN` and compact formats)
35+
- **VerhoeffChecksum** (internal) — full Verhoeff algorithm implementation with
36+
validate and computeChecksum methods
37+
- **BankAccountMasker** — full-mask and partial-mask helpers for bank account numbers
38+
- **Spring Boot demo** (`examples/spring-boot-demo/`) — REST API demo for all validators
39+
- **GitHub Actions CI** — builds and tests on Java 17 and 21, uploads JaCoCo coverage
40+
41+
[Unreleased]: https://github.com/levitasOrg/levitas-validators/compare/v0.1.0...HEAD
42+
[0.1.0]: https://github.com/levitasOrg/levitas-validators/releases/tag/v0.1.0

CONTRIBUTING.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Contributing to Levitas Validators
2+
3+
Thank you for considering a contribution! This document covers how to build the project, add a new validator, our code style, and the PR checklist.
4+
5+
## Building
6+
7+
```bash
8+
# Full build with tests and coverage check (requires Java 17+, Maven 3.9+)
9+
mvn verify
10+
11+
# Skip tests for a quick compile check
12+
mvn verify -DskipTests
13+
14+
# Run only tests
15+
mvn test
16+
```
17+
18+
The JaCoCo coverage check is enforced at 85% line coverage. New code should aim for 90%+.
19+
20+
## Adding a new validator
21+
22+
1. Create a new package under `src/main/java/io/github/levitasorg/validators/` (e.g., `tan/`).
23+
2. Implement the validator class as a final utility class (private constructor, static methods).
24+
3. Add Javadoc on every public method. At minimum: what it validates, what it returns, and null-safety contract.
25+
4. Add a corresponding test class under `src/test/java/...` mirroring the main package.
26+
5. Add tests for: null input, empty input, wrong length, invalid format, valid examples, and edge cases.
27+
6. If your validator needs bundled data (e.g., a lookup table), add a JSON resource under `src/main/resources/levitas/` and load it via Jackson in a registry class.
28+
7. Run `mvn verify` — all tests must pass and coverage must stay above 85%.
29+
30+
## Code style
31+
32+
- Java 17, no Lombok
33+
- Immutable where possible; no mutable static state after initialization
34+
- All public classes and methods must have Javadoc
35+
- Static factory methods preferred over constructors for utility-like output types
36+
- No hardcoded real Aadhaar, PAN, GSTIN, or other PII in tests — use generated or obviously-fake test data
37+
- No network calls anywhere in the library
38+
- All validators must be null-safe: `isValid(null)` returns `false`, `parse(null)` throws `IllegalArgumentException` with a clear message, `extractX(null)` returns `Optional.empty()`
39+
40+
## Test requirements
41+
42+
- 90%+ line coverage for new code
43+
- Each new public method needs at least one positive and one negative test
44+
- Null-safety tests for all public methods
45+
- Thread-safety tested for validators that will be called in concurrent contexts
46+
47+
## PR checklist
48+
49+
Before opening a pull request, verify:
50+
51+
- [ ] `mvn verify` passes locally (tests + coverage)
52+
- [ ] All new public methods have Javadoc
53+
- [ ] No real PII in test data
54+
- [ ] No network calls introduced
55+
- [ ] Code follows existing style (immutability, null safety, static utility pattern)
56+
- [ ] CHANGELOG.md updated with the change under `[Unreleased]`
57+
58+
## Issue tracker
59+
60+
Issues and feature requests: [GitHub Issues](https://github.com/levitasOrg/levitas-validators/issues)

LICENSE

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
Apache License
2+
Version 2.0, January 2004
3+
http://www.apache.org/licenses/
4+
5+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6+
7+
1. Definitions.
8+
9+
"License" shall mean the terms and conditions for use, reproduction,
10+
and distribution as defined by Sections 1 through 9 of this document.
11+
12+
"Licensor" shall mean the copyright owner or entity authorized by
13+
the copyright owner that is granting the License.
14+
15+
"Legal Entity" shall mean the union of the acting entity and all
16+
other entities that control, are controlled by, or are under common
17+
control with that entity. For the purposes of this definition,
18+
"control" means (i) the power, direct or indirect, to cause the
19+
direction or management of such entity, whether by contract or
20+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
21+
outstanding shares, or (iii) beneficial ownership of such entity.
22+
23+
"You" (or "Your") shall mean an individual or Legal Entity
24+
exercising permissions granted by this License.
25+
26+
"Source" form shall mean the preferred form for making modifications,
27+
including but not limited to software source code, documentation
28+
source, and configuration files.
29+
30+
"Object" form shall mean any form resulting from mechanical
31+
transformation or translation of a Source form, including but
32+
not limited to compiled object code, generated documentation,
33+
and conversions to other media types.
34+
35+
"Work" shall mean the work of authorship made available under
36+
the License, as indicated by a copyright notice that is included in
37+
or attached to the work (an example is provided in the Appendix below).
38+
39+
"Derivative Works" shall mean any work, whether in Source or Object
40+
form, that is based on (or derived from) the Work and for which the
41+
editorial revisions, annotations, elaborations, or other transformations
42+
represent, as a whole, an original work of authorship. For the purposes
43+
of this License, Derivative Works shall not include works that remain
44+
separable from, or merely link (or bind by name) to the interfaces of,
45+
the Work and Derivative Works thereof.
46+
47+
"Contribution" shall mean, as submitted to the Licensor for inclusion
48+
in the Work by the copyright owner or by an individual or Legal Entity
49+
authorized to submit on behalf of the copyright owner. For the purposes
50+
of this definition, "submitted" means any form of electronic, verbal,
51+
or written communication sent to the Licensor or its representatives,
52+
including but not limited to communication on electronic mailing lists,
53+
source code control systems, and issue tracking systems that are managed
54+
by, or on behalf of, the Licensor for the purpose of discussing and
55+
improving the Work, but excluding communication that is conspicuously
56+
marked or designated in writing by the copyright owner as "Not a
57+
Contribution."
58+
59+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
60+
whom a Contribution has been received by the Licensor and included
61+
within the Work.
62+
63+
2. Grant of Copyright License. Subject to the terms and conditions of
64+
this License, each Contributor hereby grants to You a perpetual,
65+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66+
copyright license to reproduce, prepare Derivative Works of,
67+
publicly display, publicly perform, sublicense, and distribute the
68+
Work and such Derivative Works in Source or Object form.
69+
70+
3. Grant of Patent License. Subject to the terms and conditions of
71+
this License, each Contributor hereby grants to You a perpetual,
72+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73+
(except as stated in this section) patent license to make, have made,
74+
use, offer to sell, sell, import, and otherwise transfer the Work,
75+
where such license applies only to those patent claims licensable
76+
by such Contributor that are necessarily infringed by their
77+
Contribution(s) alone or by the combined Contribution(s) with the
78+
Work to which such Contribution(s) was submitted. If You institute
79+
patent litigation against any entity (including a cross-claim or
80+
counterclaim in a lawsuit) alleging that the Work or any Contribution
81+
embodied within the Work constitutes patent or contributory patent
82+
infringement, then any patent licenses granted to You under this
83+
License for that Work shall terminate as of the date such litigation
84+
is filed.
85+
86+
4. Redistribution. You may reproduce and distribute copies of the
87+
Work or Derivative Works thereof in any medium, with or without
88+
modifications, and in Source or Object form, provided that You
89+
meet the following conditions:
90+
91+
(a) You must give any other recipients of the Work or Derivative
92+
Works a copy of this License; and
93+
94+
(b) You must cause any modified files to carry prominent notices
95+
stating that You changed the files; and
96+
97+
(c) You must retain, in the Source form of any Derivative Works
98+
that You distribute, all copyright, patent, trademark, and
99+
attribution notices from the Source form of the Work,
100+
excluding those notices that do not pertain to any part of
101+
the Derivative Works; and
102+
103+
(d) If the Work includes a "NOTICE" text file as part of its
104+
distribution, You must include a readable copy of the
105+
attribution notices contained within such NOTICE file, in
106+
at least one of the following places: within a NOTICE text
107+
file distributed as part of the Derivative Works; within
108+
the Source form or documentation, if provided along with the
109+
Derivative Works; or, within a display generated by the
110+
Derivative Works, if and wherever such third-party notices
111+
normally appear. The contents of the NOTICE file are for
112+
informational purposes only and do not modify the License.
113+
You may add Your own attribution notices within Derivative
114+
Works that You distribute, alongside or in addition to the
115+
NOTICE text from the Work, provided that such additional
116+
attribution notices cannot be construed as modifying the License.
117+
118+
You may add Your own license statement for Your modifications and
119+
may provide additional grant of rights to use, copy, modify, merge,
120+
publish, distribute, sublicense, and/or sell copies of Your
121+
modifications, or for such Derivative Works as a whole, under the
122+
terms of this License, if You otherwise comply with the conditions
123+
in Sections 4(a), 4(b), and 4(c) of this License.
124+
125+
5. Submission of Contributions. Unless You explicitly state otherwise,
126+
any Contribution intentionally submitted for inclusion in the Work
127+
by You to the Licensor shall be under the terms and conditions of
128+
this License, without any additional terms or conditions.
129+
Notwithstanding the above, nothing herein shall supersede or modify
130+
the terms of any separate license agreement you may have executed
131+
with Licensor regarding such Contributions.
132+
133+
6. Trademarks. This License does not grant permission to use the trade
134+
names, trademarks, service marks, or product names of the Licensor,
135+
except as required for reasonable and customary use in describing the
136+
origin of the Work and reproducing the content of the NOTICE file.
137+
138+
7. Disclaimer of Warranty. Unless required by applicable law or
139+
agreed to in writing, Licensor provides the Work (and each
140+
Contributor provides its Contributions) on an "AS IS" BASIS,
141+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
142+
implied, including, without limitation, any warranties or conditions
143+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
144+
PARTICULAR PURPOSE. You are solely responsible for determining the
145+
appropriateness of using or reproducing the Work and assume any
146+
risks associated with Your exercise of permissions under this License.
147+
148+
8. Limitation of Liability. In no event and under no legal theory,
149+
whether in tort (including negligence), contract, or otherwise,
150+
unless required by applicable law (such as deliberate and grossly
151+
negligent acts) or agreed to in writing, shall any Contributor be
152+
liable to You for damages, including any direct, indirect, special,
153+
incidental, or exemplary damages of any character arising as a
154+
result of this License or out of the use or inability to use the
155+
Work (even if such Contributor has been advised of the possibility
156+
of such damages).
157+
158+
9. Accepting Warranty or Additional Liability. While redistributing
159+
the Work or Derivative Works thereof, You may choose to offer,
160+
and charge a fee for, acceptance of support, warranty, indemnity,
161+
or other liability obligations and/or rights consistent with this
162+
License. However, in accepting such obligations, You may offer only
163+
conditions consistent with this License.
164+
165+
END OF TERMS AND CONDITIONS
166+
167+
Copyright 2024 Levitas Org
168+
169+
Licensed under the Apache License, Version 2.0 (the "License");
170+
you may not use this file except in compliance with the License.
171+
You may obtain a copy of the License at
172+
173+
http://www.apache.org/licenses/LICENSE-2.0
174+
175+
Unless required by applicable law or agreed to in writing, software
176+
distributed under the License is distributed on an "AS IS" BASIS,
177+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
178+
See the License for the specific language governing permissions and
179+
limitations under the License.

0 commit comments

Comments
 (0)