// use the pagination API to iterate over each product
// for each product, zip it up
// after you zip up all products then create the dataset zip
ProductPage page = null;
try {
page = client.getFirstPage(type);
if (page == null
|| (page != null && page.getPageProducts() == null)
|| (page != null && page.getPageProducts() != null && page
.getPageProducts().size() == 0)) {
throw new ServletException("No products for dataset: ["
+ type.getName() + "]");
}
Map productHash = new HashMap();
do {
for (Iterator i = page.getPageProducts().iterator(); i.hasNext();) {
Product product = (Product) i.next();
if (alreadyZipped(product, productHash)) {
continue;
}
Metadata metadata = null;
product.setProductReferences(client.getProductReferences(product));
metadata = client.getMetadata(product);
DataUtils.createProductZipFile(product, metadata, productDirPath);
productHash.put(product.getProductName(), ALREADY_ZIPPED);
}
page = client.getNextPage(type, page);
} while ((page != null && !page.isLastPage())
&& (page.getPageProducts() != null && page.getPageProducts().size() > 0));
} catch (Exception e) {
e.printStackTrace();
throw new ServletException(e.getMessage());
}