diff --git a/src/main/java/org/woehlke/simpleworklist/common/domain/AbstractController.java b/src/main/java/org/woehlke/simpleworklist/common/domain/AbstractController.java index a4b0cb01..53b41817 100644 --- a/src/main/java/org/woehlke/simpleworklist/common/domain/AbstractController.java +++ b/src/main/java/org/woehlke/simpleworklist/common/domain/AbstractController.java @@ -63,22 +63,22 @@ public abstract class AbstractController { @Autowired protected BreadcrumbService breadcrumbService; - //TODO: rename allCategories to allProjects @ModelAttribute("allProjects") public final List getAllCategories( @ModelAttribute("userSession") UserSessionBean userSession, BindingResult result, //TODO: remove Model model //TODO: remove ) { + userSession = updateUserSession(userSession); Context context = this.getContext(userSession); return projectService.findAllProjectsByContext(context); } - //TODO: rename rootCategories to rootProjects @ModelAttribute("rootProjects") public final List getRootCategories( @ModelAttribute("userSession") UserSessionBean userSession ) { + userSession = updateUserSession(userSession); Context context = this.getContext(userSession); return projectService.findRootProjectsByContext(context); } @@ -117,11 +117,10 @@ public final List getTaskStates(){ @ModelAttribute("context") public final String getCurrentContext( @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale + Locale locale, + Model model ){ - if(userSession == null){ - userSession = new UserSessionBean(); - } + userSession = updateUserSession(userSession); Context context = getContext(userSession); if(locale == null){ locale = Locale.ENGLISH; @@ -154,6 +153,26 @@ protected Context getContext(@NotNull final UserSessionBean userSession){ return context; } + protected UserSessionBean getNewUserSession(){ + UserAccount thisUser = this.getUser(); + long userAccountid = thisUser.getId(); + long contextId = thisUser.getDefaultContext().getId(); + UserSessionBean userSession = new UserSessionBean(userAccountid,contextId); + return userSession; + } + + protected UserSessionBean updateUserSession(UserSessionBean userSession){ + if(userSession == null){ + userSession = getNewUserSession(); + } else { + UserAccount thisUser = this.getUser(); + long contextId = thisUser.getDefaultContext().getId(); + long userAccountid = thisUser.getId(); + userSession.update(userAccountid,contextId); + } + return userSession; + } + /* protected Context getContext(UserSessionBean userSession){ UserAccount thisUser = this.getUser(); diff --git a/src/main/java/org/woehlke/simpleworklist/domain/breadcrumb/BreadcrumbServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/domain/breadcrumb/BreadcrumbServiceImpl.java index 38f1ef7b..5b172cfd 100644 --- a/src/main/java/org/woehlke/simpleworklist/domain/breadcrumb/BreadcrumbServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/domain/breadcrumb/BreadcrumbServiceImpl.java @@ -65,10 +65,20 @@ public Breadcrumb getBreadcrumbForShowOneProject(Project thisProject, Locale loc } @Override - public Breadcrumb getBreadcrumbForTaskstate(TaskState taskstate, Locale locale, UserSessionBean userSession) { + public Breadcrumb getBreadcrumbForTaskstate( + TaskState taskstate, + Locale locale, + UserSessionBean userSession + ) { log.debug("getBreadcrumbForTaskstate"); - Optional context = contextService.getContextFor(userSession); - Breadcrumb breadcrumb = new Breadcrumb(locale, context.get()); + Optional contextResult = contextService.getContextFor(userSession); + Context context; + if(contextResult.isEmpty()){ + context = null; + } else { + context = contextResult.get(); + } + Breadcrumb breadcrumb = new Breadcrumb(locale, context); String code = taskstate.getCode(); String name = messageSource.getMessage(code,null,locale); breadcrumb.addTaskstate(name,taskstate.getUrl()); diff --git a/src/main/java/org/woehlke/simpleworklist/user/session/UserSessionBean.java b/src/main/java/org/woehlke/simpleworklist/user/session/UserSessionBean.java index e15b1769..9f7c6b38 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/session/UserSessionBean.java +++ b/src/main/java/org/woehlke/simpleworklist/user/session/UserSessionBean.java @@ -27,12 +27,21 @@ public class UserSessionBean implements Serializable { private String lastSearchterm; //TODO: Make SearchRequest to Entity public UserSessionBean(){ - lastSearchterm=""; //TODO: Make SearchRequest to Entity - lastTaskState=TaskState.INBOX; - lastProjectId=0L; - lastContextId=0L; - lastTaskId=0L; - userAccountid=0L; + this.lastSearchterm=""; //TODO: Make SearchRequest to Entity + this.lastTaskState=TaskState.INBOX; + this.lastProjectId=0L; + this.lastContextId=0L; + this.lastTaskId=0L; + this.userAccountid=0L; + } + + public UserSessionBean(long userAccountid, long lastContextId){ + this.lastSearchterm=""; //TODO: Make SearchRequest to Entity + this.lastTaskState=TaskState.INBOX; + this.lastProjectId=0L; + this.lastTaskId=0L; + this.userAccountid=userAccountid; + this.lastContextId=lastContextId; } @Deprecated @@ -45,4 +54,10 @@ public UserSessionBean(long contextId){ userAccountid=0L; } + public void update(long userAccountid, long contextId) { + this.userAccountid=userAccountid; + if(this.lastContextId == 0L ){ + this.lastContextId=contextId; + } + } }