package com.mousetech.gourmetj; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.enterprise.context.SessionScoped; import javax.faces.model.SelectItem; import javax.inject.Named; import org.primefaces.PrimeFaces; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.mousetech.gourmetj.persistence.model.Category; import com.mousetech.gourmetj.persistence.model.Recipe; import com.mousetech.gourmetj.utils.TimeFormatter; @Named @SessionScoped public class UserSession implements Serializable { /** * Serial version for session save/restore */ private static final long serialVersionUID = 7449440266704831598L; /* Logger */ private static final Logger log = LoggerFactory.getLogger(UserSession.class); private String lastSearch = ""; /** * @return the lastSearch */ public String getLastSearch() { return lastSearch; } /** * @param lastSearch the lastSearch to set */ public void setLastSearch(String lastSearch) { this.lastSearch = lastSearch; } private Long lastEdit; /** * @return the lastEdit */ public Long getLastEdit() { return lastEdit; } /** * @param lastEdit the lastEdit to set */ public void setLastEdit(Long lastEdit) { this.lastEdit = lastEdit; } // *** /** * Tab index to select when presenting editDetails. First tab * is 0. */ private int detailTab; /** * @return the detailTab */ public int getDetailTab() { return detailTab; } /** * @param detailTab the detailTab to set */ public void setDetailTab(int detailTab) { this.detailTab = detailTab; } // *** private Recipe recipe; /** * Recipe is set by the mainpage bean to a blank recipe * before dispatching to the detailEdit page (new recipe). It * is also set by the detail view page so that the detail * view can be edited. * * In addition to detail editing, it's also used by the * * @see PictureController. * * @return Recipe selected. */ public Recipe getRecipe() { return recipe; } /** * @param recipe the recipe to set */ public void setRecipe(Recipe recipe) { this.recipe = recipe; } // *** private RecipeSearchType searchType = RecipeSearchType.rst_BY_NAME; /** * @return the searchType */ public RecipeSearchType getSearchType() { return searchType; } /** * @param searchType the searchType to set */ public void setSearchType(RecipeSearchType searchType) { this.searchType = searchType; } private List searchTypeList; /** * @return the searchTypeList */ public List getSearchTypeList() { if (searchTypeList == null) { searchTypeList = loadSearchTypeList(); } return searchTypeList; } private List loadSearchTypeList() { List list = new ArrayList(5); list.add(new SelectItem(RecipeSearchType.rst_BY_NAME, "Title")); list.add(new SelectItem(RecipeSearchType.rst_BY_CATEGORY, "Category")); list.add(new SelectItem(RecipeSearchType.rst_BY_CUISINE, "Cuisine")); list.add( new SelectItem(RecipeSearchType.rst_BY_INGREDIENT, "Ingredient")); return list; } // ==== public String formatCategories(Recipe r) { StringBuffer sb = new StringBuffer(30); boolean first = true; for (Category cat : r.getCategories()) { if (first) { first = false; } else { sb.append(", "); } sb.append(cat.getCategory()); } return sb.toString(); } /* * @Deprecated Using TimeConverter. */ public String formatTime(Long ltime) { return TimeFormatter.formatTime(ltime); } // Primefaces handle session timeout // Session timeout, ms (25 minutes) long sessionTimeoutInterval = 25 * 60_000L; /** * When you click the "shop" button on a recipe, it * gets added to this list. Note that it's the fully-expanded * recipe! */ private List shoppingList = new ArrayList(); /** * @return the sessionTimeoutInterval */ public long getSessionTimeoutInterval() { return sessionTimeoutInterval; } public void sessionIdleListener() { log.warn("Session Idle Listener fired."); PrimeFaces.current() .executeScript("sessionExpiredConfirmation.show()"); } public String logoutAction() { log.warn("Session Idle listener logout"); return goHome(); } public String goHome() { log.warn("E.T. Go Home!"); return "/main.jsf?faces-redirect=true"; } public List getShoppingList() { return this.shoppingList ; } }