forked from Devskiller/jfairy
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Devskiller#35 from graux/master
Support for Spanish / Spain
- Loading branch information
Showing
11 changed files
with
402 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.codearte.jfairy; | ||
|
||
import io.codearte.jfairy.producer.VATIdentificationNumberProvider; | ||
import io.codearte.jfairy.producer.company.locale.es.CIFProvider; | ||
import io.codearte.jfairy.producer.person.NationalIdentityCardNumberProvider; | ||
import io.codearte.jfairy.producer.person.PassportNumberProvider; | ||
import io.codearte.jfairy.producer.person.locale.es.DNINumberProvider; | ||
import io.codearte.jfairy.producer.person.locale.es.EsPassportNumberProvider; | ||
|
||
import java.util.Random; | ||
|
||
/** | ||
* @author graux | ||
* @since 26.04.15 | ||
*/ | ||
public class EsFairyModule extends FairyModule { | ||
|
||
public EsFairyModule(Random random) { | ||
super(random); | ||
} | ||
|
||
@Override | ||
protected void configure() { | ||
super.configure(); | ||
bind(NationalIdentityCardNumberProvider.class).to(DNINumberProvider.class); | ||
bind(VATIdentificationNumberProvider.class).to(CIFProvider.class); | ||
bind(PassportNumberProvider.class).to(EsPassportNumberProvider.class); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/io/codearte/jfairy/producer/company/locale/es/CIFProvider.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.codearte.jfairy.producer.company.locale.es; | ||
|
||
import io.codearte.jfairy.producer.VATIdentificationNumberProvider; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* @author graux | ||
* @since 26/04/2015 | ||
* Código de Identificación Fiscal (CIF) Español | ||
*/ | ||
public class CIFProvider implements VATIdentificationNumberProvider { | ||
|
||
private static final String REGEX_CIF = "^[A-Z][0-9]{2}[0-9]{5}([KPQSABEH]|[0-9]|[A-Z])$"; | ||
private Pattern regexCif; | ||
|
||
public CIFProvider() { | ||
this.regexCif = Pattern.compile(REGEX_CIF); | ||
} | ||
|
||
@Override | ||
public String get() { | ||
return String.format("%s%s%s", RandomStringUtils.randomAlphabetic(1).toUpperCase(), RandomStringUtils.randomNumeric(7), RandomStringUtils.randomAlphanumeric(1).toUpperCase()); | ||
} | ||
|
||
public boolean isValid(String cif) { | ||
return this.regexCif.matcher(cif).matches(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/io/codearte/jfairy/producer/person/locale/es/DNINumberProvider.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.codearte.jfairy.producer.person.locale.es; | ||
|
||
import io.codearte.jfairy.producer.person.NationalIdentityCardNumberProvider; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* @author graux | ||
* @since 26/04/2015 | ||
* Documento Nacional de Identidad (DNI) Español | ||
*/ | ||
public class DNINumberProvider implements NationalIdentityCardNumberProvider { | ||
|
||
private static final String REGEX_DNI = "^\\d{8}([-]?)[A-Z]$"; | ||
private Pattern regexDni; | ||
|
||
public DNINumberProvider() { | ||
this.regexDni = Pattern.compile(REGEX_DNI); | ||
} | ||
|
||
@Override | ||
public String get() { | ||
return String.format("%s-%s", RandomStringUtils.randomNumeric(8), RandomStringUtils.randomAlphabetic(1).toUpperCase()); | ||
} | ||
|
||
public boolean isValid(String dni) { | ||
return this.regexDni.matcher(dni).matches(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/io/codearte/jfairy/producer/person/locale/es/EsPassportNumberProvider.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,15 @@ | ||
package io.codearte.jfairy.producer.person.locale.es; | ||
|
||
import io.codearte.jfairy.producer.person.PassportNumberProvider; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
|
||
/** | ||
* @author graux | ||
* @since 26/04/2015 | ||
*/ | ||
public class EsPassportNumberProvider implements PassportNumberProvider { | ||
@Override | ||
public String get() { | ||
return RandomStringUtils.randomAlphanumeric(9); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
*/ | ||
public enum LanguageCode { | ||
PL, | ||
EN | ||
EN, | ||
ES | ||
} |
Oops, something went wrong.