﻿@Controller
@RequestMapping("/Service.rpc")
public class ServiceRPC extends AbstractRpcController implements ServiceRemoteService {
	private static final long serialVersionUID = -6080544323322725459L;
		
	private ProductDao productDao;
	
	@Autowired
	public void setProductDao(ProductDao pProductDao) {
		this.productDao = pProductDao;
	}

	@Override
	public RpcDataSourceResult<Map<String, String>> fetch(Map<String, String> conditions, int startRow, int EndRow, String source) {
		List<Map<String, String>> tListResult = new ArrayList<Map<String, String>>();
		
		List<Product> tProductList = productDao.getAll();
			
		for(Product tProd:tProductList){
			Map<String, String> tMap = new HashMap<String, String>();
			
			tMap.put("Product", tProd.getProduct());
			
			tListResult.add(tMap);
		}
				
		RpcDataSourceResult<Map<String, String>> tResult = new RpcDataSourceResult<Map<String, String>>();
		tResult.setStartRow(0);
		tResult.setEndRow(tListResult.size());
		tResult.setTotalRow(tListResult.size());
		tResult.setData(tListResult);
		
		return tResult;
	}
}
