Skip to content
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

Inclusion of support for Brazil #135

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/devskiller/jfairy/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ private static FairyModule getFairyModuleForLocale(DataMaster dataMaster, Locale
return new DeFairyModule(dataMaster, randomGenerator);
case KA:
return new KaFairyModule(dataMaster, randomGenerator);
case BR:
return new BrFairyModule(dataMaster, randomGenerator);
default:
LOG.info("No data for your language - using EN");
return new EnFairyModule(dataMaster, randomGenerator);
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/com/devskiller/jfairy/BrFairyModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.devskiller.jfairy;

import com.devskiller.jfairy.data.DataMaster;
import com.devskiller.jfairy.producer.RandomGenerator;
import com.devskiller.jfairy.producer.VATIdentificationNumberProvider;
import com.devskiller.jfairy.producer.company.locale.br.BrVATIdentificationNumberProvider;
import com.devskiller.jfairy.producer.person.AddressProvider;
import com.devskiller.jfairy.producer.person.NationalIdentificationNumberFactory;
import com.devskiller.jfairy.producer.person.NationalIdentityCardNumberProvider;
import com.devskiller.jfairy.producer.person.PassportNumberProvider;
import com.devskiller.jfairy.producer.person.locale.NoNationalIdentificationNumberFactory;
import com.devskiller.jfairy.producer.person.locale.br.BrAddressProvider;
import com.devskiller.jfairy.producer.person.locale.br.BrNationalIdentityCardNumberProvider;
import com.devskiller.jfairy.producer.person.locale.br.BrPassportNumberProvider;

/**
* @author Nelson Rodrigues da Silva Júnior
* @since 15.10.2020
*/
public class BrFairyModule extends FairyModule {

public BrFairyModule(DataMaster dataMaster, RandomGenerator randomGenerator) {
super(dataMaster, randomGenerator);
}

@Override
protected void configure() {
super.configure();
bind(NationalIdentificationNumberFactory.class).to(NoNationalIdentificationNumberFactory.class);
bind(NationalIdentityCardNumberProvider.class).to(BrNationalIdentityCardNumberProvider.class);
bind(VATIdentificationNumberProvider.class).to(BrVATIdentificationNumberProvider.class);
bind(AddressProvider.class).to(BrAddressProvider.class);
bind(PassportNumberProvider.class).to(BrPassportNumberProvider.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.devskiller.jfairy.producer.company.locale.br;

import java.util.Set;

import com.google.common.collect.Sets;
import com.google.inject.Inject;

import com.devskiller.jfairy.producer.BaseProducer;
import com.devskiller.jfairy.producer.VATIdentificationNumberProvider;

import static java.lang.String.valueOf;
import static java.lang.System.arraycopy;
import static org.apache.commons.lang3.StringUtils.leftPad;

/**
* Brazilian VAT Identification Number (known as the National Register of Legal Entities or CNPJ in Brazil)
*
* @author Nelson Rodrigues da Silva Júnior
* @since 15.10.2020
*/
public class BrVATIdentificationNumberProvider implements VATIdentificationNumberProvider {

private static final int EIN_LENGTH = 14;
private static final int[] pesoCNPJ = {6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2};

private BaseProducer baseProducer;

@Inject
public BrVATIdentificationNumberProvider(BaseProducer baseProducer) {
this.baseProducer = baseProducer;
}

@Override
public String get() {
return cnpj();
}

private int randomiza(int n) {
int ranNum = (int) (Math.random() * n);
return ranNum;
}

private int mod(int dividendo, int divisor) {
return (int) Math.round(dividendo - (Math.floor(dividendo / divisor) * divisor));
}

private String cnpj() {
int n = 9;
int n1 = randomiza(n);
int n2 = randomiza(n);
int n3 = randomiza(n);
int n4 = randomiza(n);
int n5 = randomiza(n);
int n6 = randomiza(n);
int n7 = randomiza(n);
int n8 = randomiza(n);
int n9 = 0; //randomiza(n);
int n10 = 0; //randomiza(n);
int n11 = 0; //randomiza(n);
int n12 = 1; //randomiza(n);
int d1 = n12 * 2 + n11 * 3 + n10 * 4 + n9 * 5 + n8 * 6 + n7 * 7 + n6 * 8 + n5 * 9 + n4 * 2 + n3 * 3 + n2 * 4 + n1 * 5;

d1 = 11 - (mod(d1, 11));

if (d1 >= 10)
d1 = 0;

int d2 = d1 * 2 + n12 * 3 + n11 * 4 + n10 * 5 + n9 * 6 + n8 * 7 + n7 * 8 + n6 * 9 + n5 * 2 + n4 * 3 + n3 * 4 + n2 * 5 + n1 * 6;

d2 = 11 - (mod(d2, 11));

if (d2 >= 10)
d2 = 0;

return "" + n1 + n2 + "." + n3 + n4 + n5 + "." + n6 + n7 + n8 + "/" + n9 + n10 + n11 + n12 + "-" + d1 + d2;
}

public boolean isValid(String cnpj) {
cnpj = cnpj.trim().replace(".", "").replace("/", "").replace("-", "");
if ((cnpj==null)||(cnpj.length()!=14)) return false;

Integer digito1 = calcularDigito(cnpj.substring(0,12), pesoCNPJ);
Integer digito2 = calcularDigito(cnpj.substring(0,12) + digito1, pesoCNPJ);
return cnpj.equals(cnpj.substring(0,12) + digito1.toString() + digito2.toString());
}

private static int calcularDigito(String str, int[] peso) {
int soma = 0;
for (int indice=str.length()-1, digito; indice >= 0; indice-- ) {
digito = Integer.parseInt(str.substring(indice,indice+1));
soma += digito*peso[peso.length-str.length()+indice];
}
soma = 11 - soma % 11;
return soma > 9 ? 0 : soma;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.devskiller.jfairy.producer.person.locale.br;

import com.devskiller.jfairy.producer.person.locale.AbstractAddress;

import static org.apache.commons.lang3.StringUtils.isNotBlank;

/**
* @author Nelson Rodrigues da Silva Júnior
* @since 15.10.2020
*/
public class BrAddress extends AbstractAddress {

public BrAddress(String streetNumber, String street, String apartmentNumber, String city, String postalCode) {
super(street, streetNumber, apartmentNumber, postalCode, city);
}

@Override
public String getAddressLine1() {
return street + ", " + streetNumber
+ (isNotBlank(apartmentNumber) ? " APT " + apartmentNumber : "");
}

@Override
public String getAddressLine2() {
return postalCode + " " + city;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.devskiller.jfairy.producer.person.locale.br;

import javax.inject.Inject;

import com.devskiller.jfairy.data.DataMaster;
import com.devskiller.jfairy.producer.BaseProducer;
import com.devskiller.jfairy.producer.person.AbstractAddressProvider;

/**
* @author Nelson Rodrigues da Silva Júnior
* @since 15.10.2020
*/
public class BrAddressProvider extends AbstractAddressProvider {

@Inject
public BrAddressProvider(DataMaster dataMaster, BaseProducer baseProducer) {
super(dataMaster, baseProducer);
}

@Override
public BrAddress get() {
return new BrAddress(getStreetNumber(), getStreet(), getApartmentNumber(),
getCity(), getPostalCode());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.devskiller.jfairy.producer.person.locale.br;

import java.util.List;

import com.google.common.collect.Lists;
import com.google.inject.Inject;

import com.devskiller.jfairy.producer.BaseProducer;
import com.devskiller.jfairy.producer.person.NationalIdentityCardNumberProvider;

import static java.lang.String.valueOf;
import static java.lang.System.arraycopy;
import static org.apache.commons.lang3.StringUtils.leftPad;

/**
* Brazilian National Identity Card Number (known as the Individual Taxpayer Register or CPF in Brazil)
*
* @author Nelson Rodrigues da Silva Júnior
* @since 15.10.2020
*/
public class BrNationalIdentityCardNumberProvider implements NationalIdentityCardNumberProvider {

private final BaseProducer baseProducer;
private static final int[] pesoCPF = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2};

@Inject
public BrNationalIdentityCardNumberProvider(BaseProducer baseProducer) {
this.baseProducer = baseProducer;
}

@Override
public String get() {
return cpf();
}

private int randomiza(int n) {
int ranNum = (int) (Math.random() * n);
return ranNum;
}

private int mod(int dividendo, int divisor) {
return (int) Math.round(dividendo - (Math.floor(dividendo / divisor) * divisor));
}

private String cpf() {
int n = 9;
int n1 = randomiza(n);
int n2 = randomiza(n);
int n3 = randomiza(n);
int n4 = randomiza(n);
int n5 = randomiza(n);
int n6 = randomiza(n);
int n7 = randomiza(n);
int n8 = randomiza(n);
int n9 = randomiza(n);
int d1 = n9 * 2 + n8 * 3 + n7 * 4 + n6 * 5 + n5 * 6 + n4 * 7 + n3 * 8 + n2 * 9 + n1 * 10;

d1 = 11 - (mod(d1, 11));

if (d1 >= 10)
d1 = 0;

int d2 = d1 * 2 + n9 * 3 + n8 * 4 + n7 * 5 + n6 * 6 + n5 * 7 + n4 * 8 + n3 * 9 + n2 * 10 + n1 * 11;

d2 = 11 - (mod(d2, 11));

if (d2 >= 10)
d2 = 0;

return "" + n1 + n2 + n3 + '.' + n4 + n5 + n6 + '.' + n7 + n8 + n9 + '-' + d1 + d2;
}

public boolean isValid(String cpf) {
cpf = cpf.trim().replace(".", "").replace("-", "");
if ((cpf==null) || (cpf.length()!=11)) return false;

for (int j = 0; j < 10; j++)
if (padLeft(Integer.toString(j), Character.forDigit(j, 10)).equals(cpf))
return false;

Integer digito1 = calcularDigito(cpf.substring(0,9), pesoCPF);
Integer digito2 = calcularDigito(cpf.substring(0,9) + digito1, pesoCPF);
return cpf.equals(cpf.substring(0,9) + digito1.toString() + digito2.toString());
}

private static int calcularDigito(String str, int[] peso) {
int soma = 0;
for (int indice=str.length()-1, digito; indice >= 0; indice-- ) {
digito = Integer.parseInt(str.substring(indice,indice+1));
soma += digito*peso[peso.length-str.length()+indice];
}
soma = 11 - soma % 11;
return soma > 9 ? 0 : soma;
}

private static String padLeft(String text, char character) {
return String.format("%11s", text).replace(' ', character);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.devskiller.jfairy.producer.person.locale.br;

import org.apache.commons.lang3.RandomStringUtils;

import com.devskiller.jfairy.producer.person.PassportNumberProvider;

/**
* @author Nelson Rodrigues da Silva Júnior
* @since 15.10.2020
*/
public class BrPassportNumberProvider implements PassportNumberProvider {

@Override
public String get() {
return RandomStringUtils.randomAlphanumeric(9);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public enum LanguageCode {
IT,
DE,
SV,
ZH
ZH,
BR
}
28 changes: 28 additions & 0 deletions src/main/resources/jfairy_br.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
alphabet: abcdefghijklmnopqrstuvwxyz
domains: [ com.br, br, app.br, blog, net.br ]
firstNames: {
male: [ José, João, Antônio, Francisco, Carlos, Paulo, Pedro, Lucas, Luiz, Marcos, Luis, Gabriel, Rafael, Daniel, Marcelo, Bruno, Eduardo, Felipe, Raimundo, Rodrigo, Nelson, Manoel, Geraldo, Roberto, Mario, Joaquim, Jorge, Sebastião, Diego, Guilherme, Fernando, Davi, Rafael, Andre, Anderson, Márcio, Gustavo, Fábio, Júlio, Renato, Alex, Igor, Douglas, Vínicios, Ricardo, Leonardo, Robson, Wilson, Mauro, Jonas, Vicente, Nicolas, Osmar, Artur, Moises, Wagner, Pablo, Willian, Ivan, Celso, Breno, Junior, Sidnei, Jaime, Alisson, Ronaldo, Romário, Neymar, Nilton, Nilson, Murilo, Sandro, Isaias, Raul, Alcides, Gean, Bernado, Arlindo, Rodolfo, Armando, Lucio, Clovis, Itamar, Magno, Vilson, Dirceu, Jonata, Enzo, Afonso, Romulo, Airton, Weliton, Ednaldo, Vilmar, Rivaldo, Juan, Abel, Tite, Savio, Roni ],
female: [ Maria, Juraci, Lucimar, Ana, Jaci, Alcione, Ivanir, Nadir, Edir, Leoni, Edi, Valdete, Reni, Eurides, Rosimar, Clair, Antonia, Francisca, Iraci, Irani, Iris, Luzimar, Geneci, Erli, Sirlei, Fernanda, Nelci, Rosinei, Gabriela, Bruna, Taina, Adria, Darli, Derci, Silva, Joseli, Juracy, Delci, Joceli, Evanir, Elis, Adriana, Rafaela, Raimunda, Edenir, Vitoria, Gabriele, Rosemar, Solimar, Ivani, Juliana, Marlei, Marley, Daniele, Gessi, Vanir, Doraci, Aline, Marcia, Irismar, Josefa, Elci, Jessica, Amanda, Renata, Raquel, Nerci, Julia, Elionai, Camila, Luana, Jacy, Eduarda, Denir, Leonor, Luciana, Gerci, Patricia, Mariana, Leticia, Erci, Iva, Jane, Cristiane, Conceicao, Aquila, Elienai, Cleidimar, Guiomar, Michele, Paula, Sirley, Silvani, Rosario, Dagmar, Daniela, Fabiana, Beatriz, Santana, Alessandra, Carla, Edy, Vanessa, Larissa, Claudia, Eroni, Luz, Lori, Joseni, Edione, Laureci, Dalci, Jaqueline ]
}
lastNames: {
male: [ Agostinho, Aguiar, Albuquerque, Alegria, Alencastro, Almada, Almeida, Alves, Alves, Alvim, Amorim, Andrade, Antunes, Aparício, Apolinário, Aragão, Araújo, Araújo, Arruda, Assis, Assunção, Ávila, Azambuja, Baptista, Barbosa, Barreto, Barros, Barros, Beira-Mar, Belchior, Belém, Bernardes, Bittencourt, Boaventura, Bonfim, Botelho, Brites, Brito, Caetano, Caldeira, Calixto, Camacho, Camilo, Campos, Capelo, Cardoso, Cardoso, Carvalho, Carvalho, Castro, Castro, Cavalcante, Cavalcanti, Chaves, Conceição, Córdoba, Corte Real, Cortês, Costa, Coutinho, Crespo, Cunha, Curado, Custódio, D’Ávila, da Conceição, da Costa, da Cruz, da Cunha, da Luz, da Mata, da Mota, da Paz, da Rocha, da Rosa, Damásio, Dantas, das Neves, Dias, Dias, Dinís, Domingues, Dorneles, dos Reis, Drumond, Duarte, Escobar, Espinosa, Esteves, Evangelista, Farias, Farias, Félix, Fernandes, Fernandes, Ferrari, Ferreira, Figueiredo, Figueiroa, Flores, Fogaça, Fogaça, Freitas, Freitas, Frutuoso, Furtado, Galvão, Garcia, Gaspar, Gentil, Geraldes, Gil, Godinho, Góis, Gomes, Gomes, Gomes, Gonçalves, Gonzaga, Goulart, Gouveia, Guedes, Guimarães, Guterres, Hernandes, Hilário, Hipólito, Ibrahim, Ilha, Infante, Jaques, Jesus, Jesus, Jordão, Lacerda, Lancastre, Leiria, Lessa, Lima, Lopes, Machado, Maciel, Magalhães, Maia, Maldonado, Marinho, Marques, Martins, Martins, Martins, Medeiros, Meireles, Mello, Melo, Mendes, Mendes, Mendes, Menezes, Mesquita, Modesto, Monteiro, Monteiro, Moraes, Morais, Moreira, Moreira, Morgado, Moura, Moura, Muniz, Nascimento, Neves, Nóbrega, Nogueira, Nogueira, Novaes, Novais, Nunes, Oliveira, Oliveira, Ornélas, Ourique, Pacheco, Padilha, Paiva, Paraíso, Paris, Peixoto, Peixoto, Peralta, Pereira, Pereira, Peres, Pilar, Pimenta, Pinheiro, Pinto, Pires, Portela, Porto, Quaresma, Quarteira, Queiroz, Ramires, Ramos, Ramos, Rebelo, Resende, Rezende, Ribeiro, Ribeiro, Ribeiro, Rocha, Rodrigues, Rodrigues, Salazar, Sales, Sales, Salgado, Salgueiro, Sampaio, Sanches, Santana, Santos, Silva, Silveira, Siqueira, Soares, Souza, Subtil, Tavares, Taveira, Teixeira, Teixeira, Teles, Torres, Trindade, Varela, Vargas, Vasconcelos, Vasques, Veiga, Veloso, Viana, Vidal, Vieira, Vieira, Vilela, Xavier, Ximenes, Xisco, Zagalo, Zaganelli, Zanette ],
female: [ Agostinho, Aguiar, Albuquerque, Alegria, Alencastro, Almada, Almeida, Alves, Alves, Alvim, Amorim, Andrade, Antunes, Aparício, Apolinário, Aragão, Araújo, Araújo, Arruda, Assis, Assunção, Ávila, Azambuja, Baptista, Barbosa, Barreto, Barros, Barros, Beira-Mar, Belchior, Belém, Bernardes, Bittencourt, Boaventura, Bonfim, Botelho, Brites, Brito, Caetano, Caldeira, Calixto, Camacho, Camilo, Campos, Capelo, Cardoso, Cardoso, Carvalho, Carvalho, Castro, Castro, Cavalcante, Cavalcanti, Chaves, Conceição, Córdoba, Corte Real, Cortês, Costa, Coutinho, Crespo, Cunha, Curado, Custódio, D’Ávila, da Conceição, da Costa, da Cruz, da Cunha, da Luz, da Mata, da Mota, da Paz, da Rocha, da Rosa, Damásio, Dantas, das Neves, Dias, Dias, Dinís, Domingues, Dorneles, dos Reis, Drumond, Duarte, Escobar, Espinosa, Esteves, Evangelista, Farias, Farias, Félix, Fernandes, Fernandes, Ferrari, Ferreira, Figueiredo, Figueiroa, Flores, Fogaça, Fogaça, Freitas, Freitas, Frutuoso, Furtado, Galvão, Garcia, Gaspar, Gentil, Geraldes, Gil, Godinho, Góis, Gomes, Gomes, Gomes, Gonçalves, Gonzaga, Goulart, Gouveia, Guedes, Guimarães, Guterres, Hernandes, Hilário, Hipólito, Ibrahim, Ilha, Infante, Jaques, Jesus, Jesus, Jordão, Lacerda, Lancastre, Leiria, Lessa, Lima, Lopes, Machado, Maciel, Magalhães, Maia, Maldonado, Marinho, Marques, Martins, Martins, Martins, Medeiros, Meireles, Mello, Melo, Mendes, Mendes, Mendes, Menezes, Mesquita, Modesto, Monteiro, Monteiro, Moraes, Morais, Moreira, Moreira, Morgado, Moura, Moura, Muniz, Nascimento, Neves, Nóbrega, Nogueira, Nogueira, Novaes, Novais, Nunes, Oliveira, Oliveira, Ornélas, Ourique, Pacheco, Padilha, Paiva, Paraíso, Paris, Peixoto, Peixoto, Peralta, Pereira, Pereira, Peres, Pilar, Pimenta, Pinheiro, Pinto, Pires, Portela, Porto, Quaresma, Quarteira, Queiroz, Ramires, Ramos, Ramos, Rebelo, Resende, Rezende, Ribeiro, Ribeiro, Ribeiro, Rocha, Rodrigues, Rodrigues, Salazar, Sales, Sales, Salgado, Salgueiro, Sampaio, Sanches, Santana, Santos, Silva, Silveira, Siqueira, Soares, Souza, Subtil, Tavares, Taveira, Teixeira, Teixeira, Teles, Torres, Trindade, Varela, Vargas, Vasconcelos, Vasques, Veiga, Veloso, Viana, Vidal, Vieira, Vieira, Vilela, Xavier, Ximenes, Xisco, Zagalo, Zaganelli, Zanette ]
}
personalEmails: [ gmail.com, hotmail.com, yahoo.com.br, uol.com.br ]
companyNames: [ Bar, Sapataria, Mercado, Padaria, Supermercado, Farmácia, Drogaria, Loja de Conveniência, Posto de Gasolina, Açougue, Mercearia, Restaurante, Perfumaria, Loja de Roupas, Mercado Central, Lanchonete, Loja de 1.99, Atacado, Mecânica, Autopeças, Basar, Açaí, Academia, Ótica, Brinquedoteca, FastFood, Boate, Boteco ]
companySuffixes: [ LTDA, Loja, Consultoria, Inc., Industria]
companyEmails: [ info, contato, escritorio, faleconosco ]

text: Este hipertexto, isto é, matriz de textos potencializados em um duplo-devir virtualizante, visa proporcionar uma combinatória proto-semântica de um discurso proposicional a partir de um universo de possíveis. Sua instauração epistemológica é traçada a posteriori pela necessidade de construir-se um conhecimento teórico escamoteado em uma base glossofônica da interioridade da razão, em conssonância com a tex-tualidade apofântica sinteticamente determinável em sua exterioridade do Ser.

telephone_number_formats: [ '##-####-####' ]

postal_code: [ '#####-###' ]

city: [ São Paulo, Rio de Janeiro, Salvador, Brasília, Fortaleza, Belo Horizonte, Manaus, Curitiba, Recife, Porto Alegre, Unaí ]

street: [ Rua Gonçalo de Carvalho, Rua das Pedras, Vieira Souto, Avenida Paulista, Rua XV de Novembro, Avenida Pedro Basso, Rua Marcelino Champagnat, Avenida Júlio Castilhos, Rua Bento Gonçalves, Rua da Aurora, Rua Portugal, Avenida Silvio Carlos Viana, Avenida Dante Michelini, Avenida Getúlio Vargas, Rua do Mucugê ]

country: [ 'Brasil' ]

language: 'BR'
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.devskiller.jfairy.producer.company.locale.br

import com.devskiller.jfairy.producer.company.locale.es.EsVATIdentificationNumberProvider
import spock.lang.Specification
import spock.lang.Unroll

/**
* @author Nelson Rodrigues da Silva Júnior
* @since 15.10.2020
*/
class BrVATIdentificationNumberProviderSpec extends Specification {

private BrVATIdentificationNumberProvider generator = new BrVATIdentificationNumberProvider()

@Unroll
def "Should validate #vatIdentificationNumber as #valid"() {

expect:
generator.isValid(vatIdentificationNumber) == valid

where:
vatIdentificationNumber | valid
"03.061.384/0001-40" | true
"03.232.334/0001-40" | false
"95.659.509/0001-57" | true
"67.706.334/0001-10" | false
}

def "Should always generate proper nip"() {
expect:
generator.isValid(generator.get())
where:
i << (1..100)
}

}
Loading