Search in sources :

Example 31 with PhoneNumberUtil

use of com.google.i18n.phonenumbers.PhoneNumberUtil in project tdq-studio-se by Talend.

the class InvalidRegCodeCountIndicatorImpl method handle.

@Override
public boolean handle(Object data) {
    super.handle(data);
    if (data == null) {
        this.invalidRegCount++;
        setMustStoreRow();
        return false;
    }
    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
    boolean parseSuccess = true;
    String regionCodeForNumber = null;
    try {
        // the parameter defualtRegion is null at here, it will get an region code when the data is guaranteed to
        // start with a '+' followed by the country calling code. e.g. "+86 13521588311", "+8613521588311",
        // "+86 1352 1588 311". or else, it will throw Exception as an invalid Region Code.
        PhoneNumber phhoneNum = phoneUtil.parse(data.toString(), null);
        regionCodeForNumber = phoneUtil.getRegionCodeForNumber(phhoneNum);
    } catch (NumberParseException e) {
        parseSuccess = false;
    }
    Set<String> supportedCountries = phoneUtil.getSupportedRegions();
    if (!parseSuccess || (!supportedCountries.contains(regionCodeForNumber))) {
        this.invalidRegCount++;
        setMustStoreRow();
    }
    return true;
}
Also used : PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Example 32 with PhoneNumberUtil

use of com.google.i18n.phonenumbers.PhoneNumberUtil in project tdq-studio-se by Talend.

the class PossiblePhoneCountIndicatorImpl method handle.

@Override
public boolean handle(Object data) {
    super.handle(data);
    if (data == null) {
        return false;
    }
    try {
        PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
        IndicatorParameters indParameters = this.getParameters();
        TextParameters textParameters = indParameters == null ? null : indParameters.getTextParameter();
        String country = IndicatorHelper.getCountryCodeByParameter(textParameters);
        PhoneNumber phoneNumeber = phoneUtil.parse(data.toString(), country);
        // number.
        if (phoneUtil.isPossibleNumber(phoneNumeber)) {
            this.possiblePhoneCount++;
            if (checkMustStoreCurrentRow() || this.checkMustStoreCurrentRow(drillDownValueCount)) {
                this.mustStoreRow = true;
            }
        }
    } catch (NumberParseException e) {
        return false;
    }
    return true;
}
Also used : TextParameters(org.talend.dataquality.indicators.TextParameters) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Example 33 with PhoneNumberUtil

use of com.google.i18n.phonenumbers.PhoneNumberUtil in project tdq-studio-se by Talend.

the class WellFormE164PhoneCountIndicatorImpl method handle.

@Override
public boolean handle(Object data) {
    super.handle(data);
    if (data == null) {
        return false;
    }
    try {
        PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
        IndicatorParameters indParameters = this.getParameters();
        TextParameters textParameters = indParameters == null ? null : indParameters.getTextParameter();
        String country = IndicatorHelper.getCountryCodeByParameter(textParameters);
        PhoneNumber phoneNumeber = phoneUtil.parse(data.toString(), country);
        String format = phoneUtil.format(phoneNumeber, PhoneNumberFormat.E164);
        if (data.toString().equals(format)) {
            wellFormE164PhoneCount++;
            if (checkMustStoreCurrentRow() || checkMustStoreCurrentRow(drillDownValueCount)) {
                this.mustStoreRow = true;
            }
        }
    } catch (NumberParseException e) {
        return false;
    }
    return true;
}
Also used : TextParameters(org.talend.dataquality.indicators.TextParameters) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Example 34 with PhoneNumberUtil

use of com.google.i18n.phonenumbers.PhoneNumberUtil in project ofbiz-framework by apache.

the class UtilMisc method splitPhoneNumber.

public static Map<String, String> splitPhoneNumber(String phoneNumber, Delegator delegator) {
    Map<String, String> result = new HashMap<>();
    try {
        PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
        String defaultCountry = EntityUtilProperties.getPropertyValue("general", "country.geo.id.default", delegator);
        GenericValue defaultGeo = EntityQuery.use(delegator).from("Geo").where("geoId", defaultCountry).cache().queryOne();
        String defaultGeoCode = defaultGeo != null ? defaultGeo.getString("geoCode") : "US";
        PhoneNumber phNumber = phoneUtil.parse(phoneNumber, defaultGeoCode);
        if (phoneUtil.isValidNumber(phNumber) || phoneUtil.isPossibleNumber(phNumber)) {
            String nationalSignificantNumber = phoneUtil.getNationalSignificantNumber(phNumber);
            int areaCodeLength = phoneUtil.getLengthOfGeographicalAreaCode(phNumber);
            result.put("countryCode", Integer.toString(phNumber.getCountryCode()));
            if (areaCodeLength > 0) {
                result.put("areaCode", nationalSignificantNumber.substring(0, areaCodeLength));
                result.put("contactNumber", nationalSignificantNumber.substring(areaCodeLength));
            } else {
                result.put("areaCode", "");
                result.put("contactNumber", nationalSignificantNumber);
            }
        } else {
            Debug.logError("Invalid phone number " + phoneNumber, module);
            result.put(ModelService.ERROR_MESSAGE, "Invalid phone number");
        }
    } catch (GenericEntityException | NumberParseException ex) {
        Debug.logError(ex, module);
        result.put(ModelService.ERROR_MESSAGE, ex.getMessage());
    }
    return result;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) HashMap(java.util.HashMap) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Example 35 with PhoneNumberUtil

use of com.google.i18n.phonenumbers.PhoneNumberUtil in project Signal-Android by WhisperSystems.

the class CurrencyUtil method getCurrencyByE164.

@Nullable
public static Currency getCurrencyByE164(@NonNull String e164) {
    PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
    Phonenumber.PhoneNumber number;
    try {
        number = PhoneNumberUtil.getInstance().parse(e164, "");
    } catch (NumberParseException e) {
        return null;
    }
    String regionCodeForNumber = phoneNumberUtil.getRegionCodeForNumber(number);
    for (Locale l : Locale.getAvailableLocales()) {
        if (l.getCountry().equals(regionCodeForNumber)) {
            return getCurrencyByLocale(l);
        }
    }
    return null;
}
Also used : Locale(java.util.Locale) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) Phonenumber(com.google.i18n.phonenumbers.Phonenumber) Nullable(androidx.annotation.Nullable)

Aggregations

PhoneNumberUtil (com.google.i18n.phonenumbers.PhoneNumberUtil)47 NumberParseException (com.google.i18n.phonenumbers.NumberParseException)34 PhoneNumber (com.google.i18n.phonenumbers.Phonenumber.PhoneNumber)23 Phonenumber (com.google.i18n.phonenumbers.Phonenumber)13 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)6 TextParameters (org.talend.dataquality.indicators.TextParameters)6 Locale (java.util.Locale)5 SuppressLint (android.annotation.SuppressLint)4 Nullable (androidx.annotation.Nullable)2 PhoneNumberOfflineGeocoder (com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder)2 RemoteLoginException (io.kamax.mxisd.exception.RemoteLoginException)2 IOException (java.io.IOException)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpPost (org.apache.http.client.methods.HttpPost)2 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)2 GenericValue (org.apache.ofbiz.entity.GenericValue)2 SpannableString (android.text.SpannableString)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1