Source:
private void exportProducts(File baseDir, Consumer consumer) throws IOException { File productDir = new File(baseDir.getCanonicalPath(), "products"); productDir.mkdir(); Map<String, Product> products = new HashMap<>(); for (Entitlement entitlement : consumer.getEntitlements()) { Pool pool = entitlement.getPool(); for (Product providedProduct : productCurator.getPoolProvidedProductsCached(pool)) { products.put(providedProduct.getId(), providedProduct); } Product product = pool.getProduct(); products.put(product.getId(), product); for (Product providedProduct : product.getProvidedProducts()) { products.put(providedProduct.getId(), providedProduct); } Product derivedProduct = pool.getDerivedProduct(); if (derivedProduct != null) { products.put(derivedProduct.getId(), derivedProduct); for (Product derivedProvidedProduct : derivedProduct.getProvidedProducts()) { products.put(derivedProvidedProduct.getId(), derivedProvidedProduct); } } for (Product derivedProvidedProduct : productCurator .getPoolDerivedProvidedProductsCached(pool)) { products.put(derivedProvidedProduct.getId(), derivedProvidedProduct); } } for (Product product : products.values()) { String path = productDir.getCanonicalPath(); String productId = product.getId(); File file = new File(path, productId + ".json"); FileWriter writer = null; try { writer = new FileWriter(file); productExporter.export(mapper, writer, product); } finally { if (writer != null) { writer.close(); } } if (StringUtils.isNumeric(product.getId())) { Owner owner = ownerCurator.findOwnerById(consumer.getOwnerId()); CertificateInfo cert = productAdapter.getProductCertificate(owner.getKey(), product.getId()); if (cert != null) { file = new File(productDir.getCanonicalPath(), product.getId() + ".pem"); writer = new FileWriter(file); productCertExporter.export(writer, cert); writer.close(); } } } }

Target:
private void exportProducts(File baseDir, Consumer consumer) throws IOException { File productDir = new File(baseDir.getCanonicalPath(), "products"); productDir.mkdir(); Map<String, Product> products = new HashMap<>(); for (Entitlement entitlement : consumer.getEntitlements()) { Pool pool = entitlement.getPool(); for (Product providedProduct : productCurator.getPoolProvidedProductsCached(pool)) { products.put(providedProduct.getId(), providedProduct); } Product product = pool.getProduct(); products.put(product.getId(), product); addProvidedProducts(product.getProvidedProducts(), products); Product derivedProduct = pool.getDerivedProduct(); if (derivedProduct != null) { products.put(derivedProduct.getId(), derivedProduct); addProvidedProducts(derivedProduct.getProvidedProducts(), products); } for (Product derivedProvidedProduct : productCurator .getPoolDerivedProvidedProductsCached(pool)) { products.put(derivedProvidedProduct.getId(), derivedProvidedProduct); } } for (Product product : products.values()) { String path = productDir.getCanonicalPath(); String productId = product.getId(); File file = new File(path, productId + ".json"); FileWriter writer = null; try { writer = new FileWriter(file); productExporter.export(mapper, writer, product); } finally { if (writer != null) { writer.close(); } } if (StringUtils.isNumeric(product.getId())) { Owner owner = ownerCurator.findOwnerById(consumer.getOwnerId()); CertificateInfo cert = productAdapter.getProductCertificate(owner.getKey(), product.getId()); if (cert != null) { file = new File(productDir.getCanonicalPath(), product.getId() + ".pem"); writer = new FileWriter(file); productCertExporter.export(writer, cert); writer.close(); } } } }