in src/main/java/com/microsoft/store/partnercenter/customers/CustomerCollectionOperations.java [158:245]
public SeekBasedResourceCollection<Customer> query(IQuery customersQuery)
{
if (customersQuery == null)
{
throw new IllegalArgumentException("customersQuery can't be null");
}
if (customersQuery.getType() == QueryType.COUNT)
{
throw new IllegalArgumentException("customersQuery can't be a count query.");
}
Collection<KeyValuePair<String, String>> parameters = new ArrayList<KeyValuePair<String, String>>();
Map<String, String> headers = new HashMap<>();
if (customersQuery.getType() == QueryType.SEEK)
{
// if this is a seek query, add the seek operation and the continuation token to the request
if (customersQuery.getToken() == null)
{
throw new IllegalArgumentException("customersQuery.Token is required.");
}
headers.put(
PartnerService.getInstance().getConfiguration().getApis().get("GetCustomers").getAdditionalHeaders().get("ContinuationToken"),
customersQuery.getToken().toString());
parameters.add(
new KeyValuePair<String, String>(
PartnerService.getInstance().getConfiguration().getApis().get("GetCustomers").getParameters().get("SeekOperation"),
customersQuery.getSeekOperation().toString()));
}
else
{
if (customersQuery.getType() == QueryType.INDEXED)
{
// if the query specifies a page size, validate it and add it to the request
ParameterValidator.isIntInclusive(
MIN_PAGE_SIZE, MAX_PAGE_SIZE,
customersQuery.getPageSize(),
MessageFormat.format(
"Allowed page size values are from {0}-{1}",
MIN_PAGE_SIZE,
MAX_PAGE_SIZE));
parameters.add(
new KeyValuePair<String, String>(
PartnerService.getInstance().getConfiguration().getApis().get("GetCustomers").getParameters().get("Size"),
String.valueOf(customersQuery.getPageSize())));
}
else
{
parameters.add(
new KeyValuePair<String, String>(
PartnerService.getInstance().getConfiguration().getApis().get("GetCustomers").getParameters().get("Size"),
"0"));
}
if (customersQuery.getFilter() != null)
{
// add the filter to the request if specified
ObjectMapper mapper = new ObjectMapper();
try
{
parameters.add(
new KeyValuePair<String, String>(
PartnerService.getInstance().getConfiguration().getApis().get("GetCustomers").getParameters().get("Filter"),
URLEncoder.encode(mapper.writeValueAsString(customersQuery.getFilter()),
"UTF-8")));
}
catch (UnsupportedEncodingException e)
{
throw new PartnerException("", null, PartnerErrorCategory.REQUEST_PARSING, e);
}
catch (JsonProcessingException e)
{
throw new PartnerException("", null, PartnerErrorCategory.REQUEST_PARSING, e);
}
}
}
return this.getPartner().getServiceClient().get(
this.getPartner(),
new TypeReference<SeekBasedResourceCollection<Customer>>(){},
PartnerService.getInstance().getConfiguration().getApis().get("GetCustomers").getPath(),
headers,
parameters);
}