* @throws ServiceException
*/
private Product buildProduct(Map<String, Object> mpp, boolean dependencies)
throws ServiceException {
Product product = buildProductBasic(mpp);
// product visibility
if(mpp.get("visibility") != null) {
Integer visi = new Integer(mpp.get("visibility").toString());
switch (visi) {
case 1:
product.setVisibility(Visibility.NOT_VISIBLE_INDIVIDUALLY);
break;
case 2:
product.setVisibility(Visibility.CATALOG);
break;
case 3:
product.setVisibility(Visibility.SEARCH);
break;
case 4:
product.setVisibility(Visibility.CATALOG_SEARCH);
break;
default:
product.setVisibility(Visibility.CATALOG_SEARCH);
break;
}
}
// set product type
if (mpp.get("type") != null) {
ProductType type = ProductTypeEnum.getTypeOf((String) mpp
.get("type"));
if (type == null && dependencies) {
/*
* means its a type not covered by the enum, so we have to look
* in magento api to get this type
*/
List<ProductType> types = listAllProductTypes();
for (ProductType productType : types) {
if (productType.getType().equals((String) mpp.get("type"))) {
type = productType;
break;
}
}
}
if (type != null)
product.setType(type);
}
// set the attributeSet
if (mpp.get("set") != null && dependencies)
product.setAttributeSet(getAttributeSet((String) mpp.get("set")));
// categories - dont get the full tree, only basic info of categories
if (mpp.get("category_ids") != null) {
if (dependencies) {
product.getCategories().addAll(
getCategoriesBasicInfo((List<Object>) mpp
.get("category_ids")));
} else {
List<Category> categories = new ArrayList<Category>();
for (Object obj : (List<Object>) mpp.get("category_ids")) {
Integer id = Integer.parseInt((String) obj);
categories.add(new Category(id));
}
product.setCategories(categories);
}
}
// Inventory
if (dependencies) {
Set<Product> products = new HashSet<Product>();
products.add(product);
getInventoryInfo(products);
}
// medias
if (dependencies)
product.setMedias(productMediaRemoteService.listByProduct(product));
// product links
if (dependencies)
product.setLinks(productLinkRemoteService.list(product));
return product;
}