package com.mousetech.gourmetj; import java.io.Serializable; import javax.enterprise.context.SessionScoped; 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; @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; } // ==== 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(); } public String formatTime(Long ltime) { if (ltime == null) { return ""; } int time = ltime.intValue(); int dd, hh, mm, ss; ss = time % 60; time /= 60; mm = time % 60; time /= 60; hh = time % 24; dd = time / 24; StringBuffer sb = new StringBuffer(20); if (dd > 0) { sb.append(dd).append("d "); } if (hh > 0) { sb.append(hh).append("h "); } if (mm > 0) { sb.append(mm); if ((ss == 0) && (hh == 0)) { sb.append(" minutes"); } else { sb.append("min. "); } } if (ss > 0) { sb.append(dd).append("sec. "); } return sb.toString().trim(); } // Primefaces handle session timeout /** * Session timeout, msec. */ private long sessionTimeoutInterval = 300000; /** * @return the sessionTimeoutInterval */ public long getSessionTimeoutInterval() { return sessionTimeoutInterval; } public void sessionIdleListener() { log.warn("Session Idle Listener fired."); PrimeFaces.current() .executeScript("sessionExpiredConfirmation.show()"); } public void logoutAction() { log.warn("Session Idle listener logout"); } }