/**
         * Filtering product lists based on product attributes
         * ?category=1
         * &manufacturer=2
         * &type=...
         * &lang=en|fr NOT REQUIRED, will use request language
         * &start=0 NOT REQUIRED, can be used for pagination
         * &count=10 NOT REQUIRED, can be used to limit item count
         * @param model
         * @param request
         * @param response
         * @return
         * @throws Exception
         */
@RequestMapping(value = "/products", method=RequestMethod.GET)
	@ResponseBody
	public ReadableProductList getFiltered(
			@RequestParam(value = "lang", required=false) String lang, 
			@RequestParam(value = "category", required=false) Long category, 
			@RequestParam(value = "manufacturer", required=false) Long manufacturer,
			@RequestParam(value = "status", required=false) String status,
			@RequestParam(value = "owner", required=false) Long owner,
			@RequestParam(value = "start", required=false) Integer start,
			@RequestParam(value = "count", required=false) Integer count,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		ProductCriteria criteria = new ProductCriteria();
		if(!StringUtils.isBlank(lang)) {
			criteria.setLanguage(lang);
		}
		if(!StringUtils.isBlank(status)) {
			criteria.setStatus(status);
		}
		if(category != null) {
			List<Long> categoryIds = new ArrayList<Long>();
			categoryIds.add(category);
			criteria.setCategoryIds(categoryIds);
		}
		if(manufacturer != null) {
			criteria.setManufacturerId(manufacturer);
		}
		if(owner != null) {
			criteria.setOwnerId(owner);
		}
		if(start != null) {
			criteria.setStartIndex(start);
		}
		if(count != null) {
			criteria.setMaxCount(count);
		}
		//TODO
		//RENTAL add filter by owner
		//REPOSITORY to use the new filters
		try {
			MerchantStore merchantStore = storeFacade.getByCode(com.salesmanager.core.business.constants.Constants.DEFAULT_STORE);
			Language language = languageUtils.getRESTLanguage(request, merchantStore);	
			ReadableProductList productList = productFacade.getProductListsByCriterias(merchantStore, language, criteria);
			return productList;
		} catch(Exception e) {
			LOGGER.error("Error while filtering products product",e);
			try {
				response.sendError(503, "Error while filtering products " + e.getMessage());
			} catch (Exception ignore) {
			}
			return null;
		}
	}
@RequestMapping(value = "/products", method=RequestMethod.GET)
@ResponseBody
public ReadableProductList getFiltered(
@RequestParam(value = "lang", required=false) String lang,
@RequestParam(value = "category", required=false) Long category,
@RequestParam(value = "manufacturer", required=false) Long manufacturer,
@RequestParam(value = "status", required=false) String status,
@RequestParam(value = "owner", required=false) Long owner,
@RequestParam(value = "start", required=false) Integer start,
@RequestParam(value = "count", required=false) Integer count,
HttpServletRequest request, HttpServletResponse response) throws Exception {
ProductCriteria criteria = new ProductCriteria();
if(!StringUtils.isBlank(lang)) {
criteria.setLanguage(lang);
}
if(!StringUtils.isBlank(status)) {
criteria.setStatus(status);
}
if(category != null) {
List<Long> categoryIds = new ArrayList<Long>();
categoryIds.add(category);
criteria.setCategoryIds(categoryIds);
}
if(manufacturer != null) {
criteria.setManufacturerId(manufacturer);
}
if(owner != null) {
criteria.setOwnerId(owner);
}
if(start != null) {
criteria.setStartIndex(start);
}
if(count != null) {
criteria.setMaxCount(count);
}
//TODO
//RENTAL add filter by owner
//REPOSITORY to use the new filters
try {
MerchantStore merchantStore = storeFacade.getByCode(com.salesmanager.core.business.constants.Constants.DEFAULT_STORE);
Language language = languageUtils.getRESTLanguage(request, merchantStore);
ReadableProductList productList = productFacade.getProductListsByCriterias(merchantStore, language, criteria);
return productList;
} catch(Exception e) {
LOGGER.error("Error while filtering products product",e);
try {
response.sendError(503, "Error while filtering products " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
@RequestMapping(value = "/products", method=RequestMethod.GET)
@ResponseBody
public ReadableProductList getFiltered(
@RequestParam(value = "lang", required=false) String lang,
@RequestParam(value = "category", required=false) Long category,
@RequestParam(value = "manufacturer", required=false) Long manufacturer,
@RequestParam(value = "status", required=false) String status,
@RequestParam(value = "owner", required=false) Long owner,
@RequestParam(value = "start", required=false) Integer start,
@RequestParam(value = "count", required=false) Integer count,
HttpServletRequest request, HttpServletResponse response) throws Exception {
ProductCriteria criteria = new ProductCriteria();
if(!StringUtils.isBlank(lang)) {
criteria.setLanguage(lang);
}
if(!StringUtils.isBlank(status)) {
criteria.setStatus(status);
}
if(category != null) {
List<Long> categoryIds = new ArrayList<Long>();
categoryIds.add(category);
criteria.setCategoryIds(categoryIds);
}
if(manufacturer != null) {
criteria.setManufacturerId(manufacturer);
}
if(owner != null) {
criteria.setOwnerId(owner);
}
if(start != null) {
criteria.setStartIndex(start);
}
if(count != null) {
criteria.setMaxCount(count);
}
//TODO
//RENTAL add filter by owner
//REPOSITORY to use the new filters
try {
MerchantStore merchantStore = storeFacade.getByCode(com.salesmanager.core.business.constants.Constants.DEFAULT_STORE);
Language language = languageUtils.getRESTLanguage(request, merchantStore);
ReadableProductList productList = productFacade.getProductListsByCriterias(merchantStore, language, criteria);
return productList;
} catch(Exception e) {
LOGGER.error("Error while filtering products product",e);
try {
response.sendError(503, "Error while filtering products " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
@RequestMapping(value = "/products", method=RequestMethod.GET)
@ResponseBody
public ReadableProductList getFiltered(
@RequestParam(value = "lang", required=false) String lang,
@RequestParam(value = "category", required=false) Long category,
@RequestParam(value = "manufacturer", required=false) Long manufacturer,
@RequestParam(value = "status", required=false) String status,
@RequestParam(value = "owner", required=false) Long owner,
@RequestParam(value = "start", required=false) Integer start,
@RequestParam(value = "count", required=false) Integer count,
HttpServletRequest request, HttpServletResponse response) throws Exception {
ProductCriteria criteria = new ProductCriteria();
if(!StringUtils.isBlank(lang)) {
criteria.setLanguage(lang);
}
if(!StringUtils.isBlank(status)) {
criteria.setStatus(status);
}
if(category != null) {
List<Long> categoryIds = new ArrayList<Long>();
categoryIds.add(category);
criteria.setCategoryIds(categoryIds);
}
if(manufacturer != null) {
criteria.setManufacturerId(manufacturer);
}
if(owner != null) {
criteria.setOwnerId(owner);
}
if(start != null) {
criteria.setStartIndex(start);
}
if(count != null) {
criteria.setMaxCount(count);
}
//TODO
//RENTAL add filter by owner
//REPOSITORY to use the new filters
try {
MerchantStore merchantStore = storeFacade.getByCode(com.salesmanager.core.business.constants.Constants.DEFAULT_STORE);
Language language = languageUtils.getRESTLanguage(request, merchantStore);
ReadableProductList productList = productFacade.getProductListsByCriterias(merchantStore, language, criteria);
return productList;
} catch(Exception e) {
LOGGER.error("Error while filtering products product",e);
try {
response.sendError(503, "Error while filtering products " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}