Send a Lookup request

@param phoneNumber phone number is for viewing lookup
@return Lookup
@throws UnauthorizedException if client is unauthorized
@throws GeneralException      general exception
772416
public Lookup viewLookup(final BigInteger phoneNumber) throws UnauthorizedException, GeneralException, NotFoundException {
        if (phoneNumber == null) {
            throw new IllegalArgumentException("PhoneNumber must be specified.");
        }
        final Lookup lookup = new Lookup(phoneNumber);
        return this.viewLookup(lookup);
    }
86324
private static String toInternational(PhoneNumber phoneNumber) throws PhoneNumberException {
		String number = phoneNumber.getNumber();
		if (number.startsWith("+") || number.length() == INTERNATIONAL_FORMAT_LENGTH) {
			return StringUtils.leftPad(number.replace("+", "").replaceAll("\\s+", ""), INTERNATIONAL_FORMAT_LENGTH, '0');
		} else {
			throw new IllegalArgumentException("Invalid phone number. OVH only accepts international phone numbers. Please write the phone number with the country prefix. "
					+ "For example, if the number is 0601020304 and it is a French number, then the international number is +33601020304");
		}
	}
1328230
@Override
    public ResourceSet<PhoneNumber> read(final TwilioRestClient client) {
        return new ResourceSet<>(this, client, firstPage(client));
    }
742273
@Override
    public List<PhoneNumber> searchForNumbers(String country, PhoneNumberSearchFilters listFilters) {
        if(logger.isDebugEnabled()) {
            logger.debug("searchPattern " + listFilters.getFilterPattern());
        }
        Pattern filterPattern = listFilters.getFilterPattern();
        String filterPatternString = null;
        if(filterPattern != null) {
            filterPatternString = filterPattern.toString().replaceAll("[^\\d]", "");
        }
        if(logger.isDebugEnabled()) {
            logger.debug("searchPattern simplified for nexmo " + filterPatternString);
        }

        String queryUri = searchURI + country;
        boolean queryParamAdded = false;
        if(("US".equalsIgnoreCase(country) || "CA".equalsIgnoreCase(country)) && listFilters.getAreaCode() != null) {
            // https://github.com/Mobicents/RestComm/issues/551 fixing the search pattern for US when Area Code is selected
            // https://github.com/Mobicents/RestComm/issues/602 fixing the search pattern for CA when Area Code is selected
            queryUri = queryUri + "?pattern=1" + listFilters.getAreaCode() + "&search_pattern=0";
            queryParamAdded = true;
        } else if(filterPatternString != null) {
            queryUri = queryUri + "?pattern=" + filterPatternString + "&search_pattern=1";
            queryParamAdded = true;
        }
        if(listFilters.getSmsEnabled() != null || listFilters.getVoiceEnabled() != null) {
            if(!queryParamAdded) {
                queryUri = queryUri + "?";
                queryParamAdded = true;
            } else {
                queryUri = queryUri + "&";
            }
            if(listFilters.getSmsEnabled() != null && listFilters.getVoiceEnabled() != null) {
                queryUri = queryUri + "features=SMS,VOICE";
            } else if(listFilters.getSmsEnabled() != null) {
                queryUri = queryUri + "features=SMS";
            } else {
                queryUri = queryUri + "features=VOICE";
            }
        }
        if(listFilters.getRangeIndex() != -1) {
            if(!queryParamAdded) {
                queryUri = queryUri + "?";
                queryParamAdded = true;
            } else {
                queryUri = queryUri + "&";
            }
            queryUri = queryUri + "index=" + listFilters.getRangeIndex();
        }
        if(listFilters.getRangeSize() != -1) {
            if(!queryParamAdded) {
                queryUri = queryUri + "?";
                queryParamAdded = true;
            } else {
                queryUri = queryUri + "&";
            }
            queryUri = queryUri + "size=" + listFilters.getRangeSize();
        }
        final HttpGet get = new HttpGet(queryUri);
        try {

            final DefaultHttpClient client = new DefaultHttpClient();
//                if (telestaxProxyEnabled) {
//                    // This will work as a flag for LB that this request will need to be modified and proxied to VI
//                    get.addHeader("TelestaxProxy", String.valueOf(telestaxProxyEnabled));
//                    // This will tell LB that this request is a getAvailablePhoneNumberByAreaCode request
//                    get.addHeader("RequestType", "GetAvailablePhoneNumbersByAreaCode");
//                    //This will let LB match the DID to a node based on the node host+port
//                    for (SipURI uri: containerConfiguration.getOutboundInterfaces()) {
//                        get.addHeader("OutboundIntf", uri.getHost()+":"+uri.getPort()+":"+uri.getTransportParam());
//                    }
//                }
            if(logger.isDebugEnabled()) {
                logger.debug("Nexmo query " + queryUri);
            }
            final HttpResponse response = client.execute(get);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                final String content = StringUtils.toString(response.getEntity().getContent());
                JsonParser parser = new JsonParser();
                JsonObject jsonResponse = parser.parse(content).getAsJsonObject();
                if(logger.isDebugEnabled()) {
                    logger.debug("Nexmo response " + jsonResponse.toString());
                }
                JsonPrimitive countPrimitive = jsonResponse.getAsJsonPrimitive("count");
                if(countPrimitive == null) {
                    if(logger.isDebugEnabled()) {
                        logger.debug("No numbers found");
                    }
                    return new ArrayList<PhoneNumber>();
                }
                long count = countPrimitive.getAsLong();
                if(logger.isDebugEnabled()) {
                    logger.debug("Number of numbers found : "+count);
                }
                JsonArray nexmoNumbers = jsonResponse.getAsJsonArray("numbers");
                final List<PhoneNumber> numbers = toAvailablePhoneNumbers(nexmoNumbers, listFilters);
                return numbers;
            } else {
                logger.warn("Couldn't reach uri for getting Phone Numbers. Response status was: "+response.getStatusLine().getStatusCode());
            }
        } catch (final Exception e) {
            logger.warn("Couldn't reach uri for getting Phone Numbers" + uri, e);
        }

        return new ArrayList<PhoneNumber>();
    }
517050
public Iterable<DUser> queryByPhoneNumber1(java.lang.String phoneNumber1) {
    return queryByField(null, DUserMapper.Field.PHONENUMBER1.getFieldName(), phoneNumber1);
  }
24447
private Page<AvailablePhoneNumberCountry> pageForRequest(final TwilioRestClient client, final Request request) {
        Response response = client.request(request);

        if (response == null) {
            throw new ApiConnectionException("AvailablePhoneNumberCountry read failed: Unable to connect to server");
        } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) {
            RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper());
            if (restException == null) {
                throw new ApiException("Server Error, no content");
            }

            throw new ApiException(
                restException.getMessage(),
                restException.getCode(),
                restException.getMoreInfo(),
                restException.getStatus(),
                null
            );
        }

        return Page.fromJson(
            "countries",
            response.getContent(),
            AvailablePhoneNumberCountry.class,
            client.getObjectMapper()
        );
    }
442438
public static <T extends AVUser> Observable<T> signUpOrLoginByMobilePhoneInBackground(String mobilePhoneNumber, String smsCode, Class<T> clazz) {
    if (StringUtil.isEmpty(mobilePhoneNumber)) {
      return Observable.error(new IllegalArgumentException(String.format(ILLEGALARGUMENT_MSG_FORMAT, "mobilePhoneNumber")));
    }
    if (StringUtil.isEmpty(smsCode)) {
      return Observable.error(new IllegalArgumentException(String.format(ILLEGALARGUMENT_MSG_FORMAT, "smsCode")));
    }
    if (null == clazz) {
      return Observable.error(new IllegalArgumentException(String.format(ILLEGALARGUMENT_MSG_FORMAT, "clazz")));
    }
    Map<String, Object> params = createUserMap(null, null, null, mobilePhoneNumber, smsCode);
    JSONObject data = new JSONObject(params);
    return PaasClient.getStorageClient().signUpOrLoginByMobilephone(data, clazz);
  }
1264364
public static base_response renumber(nitro_service client) throws Exception {
		nspbrs renumberresource = new nspbrs();
		return renumberresource.perform_operation(client,"renumber");
	}
760830
@Override
    public List<Address> lookupAddress(final NominatimLookupRequest lookup) throws IOException {

        final String apiCall = String.format("%s&%s", lookupUrl, lookup.getQueryString());
        LOGGER.debug("lookup url: {}", apiCall);
        final HttpGet req = new HttpGet(apiCall);
        return httpClient.execute(req, defaultLookupHandler);
    }
635974
public static base_response renumber(nitro_service client) throws Exception {
		nspbr6 renumberresource = new nspbr6();
		return renumberresource.perform_operation(client,"renumber");
	}
397843
public static org.restcomm.connect.provisioning.number.api.PhoneNumber convertIncomingPhoneNumbertoPhoneNumber(IncomingPhoneNumber incomingPhoneNumber) {
        return new org.restcomm.connect.provisioning.number.api.PhoneNumber(
                incomingPhoneNumber.getFriendlyName(),
                incomingPhoneNumber.getPhoneNumber(),
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                incomingPhoneNumber.isVoiceCapable(),
                incomingPhoneNumber.isSmsCapable(),
                incomingPhoneNumber.isMmsCapable(),
                incomingPhoneNumber.isFaxCapable(),
                false);
    }
1224633
@RequestMapping(value = PhoneNumber.PARSE_AND_FORMAT, method = RequestMethod.GET)
  @PermitAll
  public PhoneNumberDataWithFormats parseAndFormatPhoneNumber(
      @RequestParam(value = Parameters.LANGUAGE, required = true) final String planguage,
      @RequestParam(value = Parameters.COUNTRY, required = true) final String pcountry,
      @RequestParam(value = Parameters.PHONE_NUMBER, required = true) final String pphoneNumber) {
    final PhoneNumberDataWithFormats result = new PhoneNumberDataWithFormats(phoneNumberUtil
        .parsePhoneNumber(pphoneNumber, pcountry, LocaleUtil.convertLanguageToLocale(planguage)));
    result.setCommonInternational(phoneNumberUtil.formatCommonInternational(result));
    result.setCommonNational(phoneNumberUtil.formatCommonNational(result));
    result.setDin5008International(phoneNumberUtil.formatDin5008International(result));
    result.setDin5008National(phoneNumberUtil.formatDin5008National(result));
    result.setE123International(phoneNumberUtil.formatE123International(result));
    result.setE123National(phoneNumberUtil.formatE123National(result));
    result.setMs(phoneNumberUtil.formatMs(result));
    result.setUrl(phoneNumberUtil.formatUrl(result));
    return result;
  }
1310945
public byte[] sendQuerySm(OutputStream os, int sequenceNumber,
            String messageId, TypeOfNumber sourceAddrTon,
            NumberingPlanIndicator sourceAddrNpi, String sourceAddr)
            throws PDUStringException, IOException {
        synchronized (os) {
            return pduSender.sendQuerySm(os, sequenceNumber, messageId,
                    sourceAddrTon, sourceAddrNpi, sourceAddr);
        }
    }
754905
public Iterable<DUser> queryByPhoneNumber2(java.lang.String phoneNumber2) {
    return queryByField(null, DUserMapper.Field.PHONENUMBER2.getFieldName(), phoneNumber2);
  }
1000373
public Sms from(String name, String phoneNumber) {
		return from(name, new PhoneNumber(phoneNumber));
	}
481019
public void setPhoneNumber(String number) {
		String phoneNumber = number;
		if(number.startsWith("+")) {			
			phoneNumber = phoneNumber.substring(1);
		}
		try {
			basePhoneNumber(phoneNumber);		
			telUrl.setPhoneNumber(phoneNumber);
		} catch (ParseException ex) {
			logger.error("Error setting phone number " + number);
			throw new java.lang.IllegalArgumentException("phone number " + number + " is invalid", ex);
		}
	}
675498
public PhoneNumberProvisioningManager get() {
        PhoneNumberProvisioningManager manager = (PhoneNumberProvisioningManager) context.getAttribute("PhoneNumberProvisioningManager");
        if (manager != null) // ok, it's already in the context. Return it
            return manager;
        manager = create();
        // put it into the context for next time that is requested
        context.setAttribute("PhoneNumberProvisioningManager", manager);
        return manager;
    }