public void setEntity(Recipe recipe) {
super.setEntity(recipe);
if(recipe != null) {
EntityCachingManager cache = getCache();
final Project project = recipe.getProject();
// Load QuantityTypes if not already loaded
cache.get(QuantityType.class, true, new CacheLoader<QuantityType>() {
public List<QuantityType> onCacheLoad() {
return QuantityTypeDAO.getQuantityTypeByProject(project);
}
});
foodItemSet.clear();
if(recipe.getRecipeItems() != null) {
Map<Key, KeyEntity> foodItemMap = cache.get(FoodItem.class);
for(RecipeItem item : recipe.getRecipeItems()) {
if(foodItemMap.containsKey(item.getFoodItemKey())) {
FoodItem foodItem = (FoodItem)foodItemMap.get(item.getFoodItemKey());
FoodItemWrapper foodItemWrapper = new FoodItemWrapper(project, foodItem, item);
foodItemSet.add(foodItemWrapper);