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

Add locale for GE #92

Merged
merged 5 commits into from
Nov 15, 2017
Merged
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
6 changes: 2 additions & 4 deletions src/main/java/io/codearte/jfairy/Bootstrap.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.codearte.jfairy;

import com.google.common.base.Optional;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provider;
Expand All @@ -9,15 +8,12 @@
import io.codearte.jfairy.data.MapBasedDataMaster;
import io.codearte.jfairy.producer.RandomGenerator;
import io.codearte.jfairy.producer.util.LanguageCode;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.apache.commons.math3.random.RandomDataGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import java.io.IOException;
import java.util.Locale;
import java.util.Random;

/**
* <p>Using a {@link #builder()}, you can configure the following fields:</p>
Expand Down Expand Up @@ -147,6 +143,8 @@ private static FairyModule getFairyModuleForLocale(DataMaster dataMaster, Locale
return new ZhFairyModule(dataMaster, randomGenerator);
case DE:
return new DeFairyModule(dataMaster, randomGenerator);
case KA:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the language code GE or KA?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the PR description, this a rare case where a name of the country and language differs. 'GE' is the country (ISO 3166) , 'KA' is the language (https://www.loc.gov/standards/iso639-2/php/langcodes_name.php?iso_639_1=ka).

Copy link
Contributor

@OlgaMaciaszek OlgaMaciaszek Nov 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Looking back at it, the way it's done right now is inconsistent. We use language codes, while the fairy modules really represent specific locale, not only languages. I think you can keep either KA or GE here, but soon we should modify these enums to represent both language and country, cause there can be different document formats in same language speaking countries. However, either way, I would only stick with one of them for now till we get it fixed. Please choose one and stick to it in all your changes.

Copy link
Contributor Author

@EduardRindt-4F EduardRindt-4F Nov 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there is not much to be decided. The Georgian locale must have the 'ka' language as per ISO-639. If I don't want to change the language-to-module deduction logic in Bootstrap.getFairyModuleForLocale(...) as well as the parser of control YAMLs, I have to stay with ka.
I do not like it (KaFairyModule etc. is counter-intuitive), but I shall follow your rules.
See my latest commit, please.

return new KaFairyModule(dataMaster, randomGenerator);
default:
LOG.info("No data for your language - using EN");
return new EnFairyModule(dataMaster, randomGenerator);
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/io/codearte/jfairy/KaFairyModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.codearte.jfairy;

import io.codearte.jfairy.data.DataMaster;
import io.codearte.jfairy.producer.RandomGenerator;
import io.codearte.jfairy.producer.VATIdentificationNumberProvider;
import io.codearte.jfairy.producer.company.locale.ka.KaVATIdentificationNumberProvider;
import io.codearte.jfairy.producer.person.AddressProvider;
import io.codearte.jfairy.producer.person.NationalIdentificationNumberFactory;
import io.codearte.jfairy.producer.person.NationalIdentityCardNumberProvider;
import io.codearte.jfairy.producer.person.PassportNumberProvider;
import io.codearte.jfairy.producer.person.locale.NoNationalIdentificationNumberFactory;
import io.codearte.jfairy.producer.person.locale.ka.KaAddressProvider;
import io.codearte.jfairy.producer.person.locale.ka.KaNationalIdentityCardNumberProvider;
import io.codearte.jfairy.producer.person.locale.ka.KaPassportNumberProvider;

public class KaFairyModule extends FairyModule {

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

@Override
protected void configure() {
super.configure();
bind(NationalIdentificationNumberFactory.class).to(NoNationalIdentificationNumberFactory.class);
bind(NationalIdentityCardNumberProvider.class).to(KaNationalIdentityCardNumberProvider.class);
bind(VATIdentificationNumberProvider.class).to(KaVATIdentificationNumberProvider.class);
bind(AddressProvider.class).to(KaAddressProvider.class);
bind(PassportNumberProvider.class).to(KaPassportNumberProvider.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.codearte.jfairy.producer.company.locale.ka;

import com.google.inject.Inject;
import io.codearte.jfairy.producer.BaseProducer;
import io.codearte.jfairy.producer.VATIdentificationNumberProvider;

public class KaVATIdentificationNumberProvider implements VATIdentificationNumberProvider {

private final BaseProducer baseProducer;

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

@Override
public String get() {
return baseProducer.randomElement("2", "4") + baseProducer.numerify("########");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.codearte.jfairy.producer.person.locale;

import io.codearte.jfairy.producer.person.Address;

/**
* A base of all addresses. It carries all needed fields, but leaves most of formatting to subclasses.
*/
public abstract class AbstractAddress implements Address {
protected final String street;
protected final String streetNumber;
protected final String apartmentNumber;
protected final String postalCode;
protected final String city;

public AbstractAddress(String street, String streetNumber, String apartmentNumber, String postalCode, String city) {
this.street = street;
this.streetNumber = streetNumber;
this.postalCode = postalCode;
this.city = city;
this.apartmentNumber = apartmentNumber;
}

public String getStreet() {
return street;
}

public String getStreetNumber() {
return streetNumber;
}

public String getApartmentNumber() {
return apartmentNumber;
}

public String getPostalCode() {
return postalCode;
}

public String getCity() {
return city;
}

public abstract String getAddressLine1();

public abstract String getAddressLine2();

@Override
public String toString() {
return getAddressLine1() + System.lineSeparator() + getAddressLine2();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.codearte.jfairy.producer.person.locale;

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

/**
* An address format typical for European countries but the UK and ex-Soviet union.
*/
public abstract class ContinentalAddress extends AbstractAddress {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if 2 levels of abstractions are needed here. Maybe it would be better to leave the implementation of the methods that most countries use in AbstractAddress, and just override it in Ge, En and Zh?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the order of address parts ( street > number, ZIP > city) is really quite common for European countries, but nowhere else.
What is wrong with one intermediate class shared by four implementations?

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

protected abstract String getApartmentMark();

protected String getStreetNumberSeparator() {
return " ";
}

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

@Override
public String getAddressLine2() {
return postalCode + " " + city;
}
}
Original file line number Diff line number Diff line change
@@ -1,65 +1,22 @@
package io.codearte.jfairy.producer.person.locale.de;

import io.codearte.jfairy.producer.person.Address;
import io.codearte.jfairy.producer.person.locale.ContinentalAddress;

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

/**
* @author Roland Weisleder
*/
public class DeAddress implements Address {

private final String streetNumber;

private final String street;

private final String apartmentNumber;

private final String city;

private final String postalCode;
public class DeAddress extends ContinentalAddress {

public DeAddress(String streetNumber, String street, String apartmentNumber, String city, String postalCode) {
this.streetNumber = streetNumber;
this.street = street;
this.apartmentNumber = apartmentNumber;
this.city = city;
this.postalCode = postalCode;
}

public String getStreetNumber() {
return streetNumber;
}

public String getStreet() {
return street;
}

public String getApartmentNumber() {
return apartmentNumber;
}

public String getCity() {
return city;
}

public String getPostalCode() {
return postalCode;
}

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

public String getAddressLine2() {
return postalCode + " " + city;
super(street, streetNumber, apartmentNumber, postalCode, city);
}

@Override
public String toString() {
return getAddressLine1() + LINE_SEPARATOR + getAddressLine2();
protected String getApartmentMark() {
return ", ";
}

}
Original file line number Diff line number Diff line change
@@ -1,61 +1,25 @@
package io.codearte.jfairy.producer.person.locale.en;

import io.codearte.jfairy.producer.person.Address;
import io.codearte.jfairy.producer.person.locale.AbstractAddress;

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

public class EnAddress implements Address {

private final String streetNumber;

private final String street;

private final String apartmentNumber;

private final String city;

private final String postalCode;
public class EnAddress extends AbstractAddress {

public EnAddress(String streetNumber, String street, String apartmentNumber, String city, String postalCode) {
this.streetNumber = streetNumber;
this.street = street;
this.apartmentNumber = apartmentNumber;
this.city = city;
this.postalCode = postalCode;
}

public String getStreetNumber() {
return streetNumber;
}

public String getStreet() {
return street;
}

public String getApartmentNumber() {
return apartmentNumber;
}

public String getCity() {
return city;
}

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

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

@Override
public String getAddressLine2() {
return city + " " + postalCode;
}

@Override
public String toString() {
return getAddressLine1() + LINE_SEPARATOR + getAddressLine2();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,25 @@
package io.codearte.jfairy.producer.person.locale.es;

import io.codearte.jfairy.producer.person.Address;
import io.codearte.jfairy.producer.person.locale.ContinentalAddress;

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

public class EsAddress implements Address {

private final String street;

private final String streetNumber;

private final String apartmentNumber;

private final String postalCode;

private final String city;

public class EsAddress extends ContinentalAddress {

public EsAddress(String street, String streetNumber, String apartmentNumber, String postalCode, String city) {
this.street = street;
this.streetNumber = streetNumber;
this.apartmentNumber = apartmentNumber;
this.postalCode = postalCode;
this.city = city;
}

public String getStreet() {
return street;
}

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

public String getApartmentNumber() {
return apartmentNumber;
}

public String getPostalCode() {
return postalCode;
}

public String getCity() {
return city;
}

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

public String getAddressLine2() {
return postalCode + " " + city;
@Override
protected String getStreetNumberSeparator() {
return ", ";
}

@Override
public String toString() {
return getAddressLine1() + LINE_SEPARATOR + getAddressLine2();
public String getApartmentMark() {
return " ";
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.codearte.jfairy.producer.person.locale.ka;

import io.codearte.jfairy.producer.person.locale.AbstractAddress;

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

public class KaAddress extends AbstractAddress {
public KaAddress(String street, String streetNumber, String apartmentNumber, String postalCode, String city) {
super(street, streetNumber, apartmentNumber, postalCode, city);
}

@Override
public String getAddressLine1() {
return postalCode + ", " + city;
}

@Override
public String getAddressLine2() {
return street + " №" + streetNumber + (isNotBlank(apartmentNumber) ? ", ბინა " + apartmentNumber : "");
}
}
Loading