*
* @param sub source subscription
* @return pool for subscription
*/
public static Pool copyFromSub(Subscription sub) {
Pool p = new Pool(sub.getOwner(), sub.getProduct().getId(),
sub.getProduct().getName(), new HashSet<ProvidedProduct>(),
sub.getQuantity(), sub.getStartDate(),
sub.getEndDate(), sub.getContractNumber(), sub.getAccountNumber(),
sub.getOrderNumber());
p.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
for (ProductAttribute attr : sub.getProduct().getAttributes()) {
p.addProductAttribute(new ProductPoolAttribute(attr.getName(), attr.getValue(),
sub.getProduct().getId()));
}
// Copy sub-product data if there is any:
if (sub.getDerivedProduct() != null) {
p.setDerivedProductId(sub.getDerivedProduct().getId());
p.setDerivedProductName(sub.getDerivedProduct().getName());
for (ProductAttribute attr : sub.getDerivedProduct().getAttributes()) {
p.addSubProductAttribute(new DerivedProductPoolAttribute(attr.getName(),
attr.getValue(), sub.getProduct().getId()));
}
}
for (Product prod : sub.getProvidedProducts()) {
p.addProvidedProduct(new ProvidedProduct(prod.getId(), prod.getName()));
}
for (Branding b : sub.getBranding()) {
p.getBranding().add(new Branding(b.getProductId(), b.getType(), b.getName()));
}
return p;
}