Skip to content

Commit e8c56c4

Browse files
Merge pull request #336 from Spring-Framework-Java-Apps/master
## 2.3.34
2 parents 1fb604c + a788a0a commit e8c56c4

File tree

3 files changed

+59
-15
lines changed

3 files changed

+59
-15
lines changed

src/main/java/org/woehlke/simpleworklist/common/domain/AbstractController.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ public abstract class AbstractController {
6363
@Autowired
6464
protected BreadcrumbService breadcrumbService;
6565

66-
//TODO: rename allCategories to allProjects
6766
@ModelAttribute("allProjects")
6867
public final List<Project> getAllCategories(
6968
@ModelAttribute("userSession") UserSessionBean userSession,
7069
BindingResult result, //TODO: remove
7170
Model model //TODO: remove
7271
) {
72+
userSession = updateUserSession(userSession);
7373
Context context = this.getContext(userSession);
7474
return projectService.findAllProjectsByContext(context);
7575
}
7676

77-
//TODO: rename rootCategories to rootProjects
7877
@ModelAttribute("rootProjects")
7978
public final List<Project> getRootCategories(
8079
@ModelAttribute("userSession") UserSessionBean userSession
8180
) {
81+
userSession = updateUserSession(userSession);
8282
Context context = this.getContext(userSession);
8383
return projectService.findRootProjectsByContext(context);
8484
}
@@ -117,11 +117,10 @@ public final List<TaskState> getTaskStates(){
117117
@ModelAttribute("context")
118118
public final String getCurrentContext(
119119
@ModelAttribute("userSession") UserSessionBean userSession,
120-
Locale locale
120+
Locale locale,
121+
Model model
121122
){
122-
if(userSession == null){
123-
userSession = new UserSessionBean();
124-
}
123+
userSession = updateUserSession(userSession);
125124
Context context = getContext(userSession);
126125
if(locale == null){
127126
locale = Locale.ENGLISH;
@@ -154,6 +153,26 @@ protected Context getContext(@NotNull final UserSessionBean userSession){
154153
return context;
155154
}
156155

156+
protected UserSessionBean getNewUserSession(){
157+
UserAccount thisUser = this.getUser();
158+
long userAccountid = thisUser.getId();
159+
long contextId = thisUser.getDefaultContext().getId();
160+
UserSessionBean userSession = new UserSessionBean(userAccountid,contextId);
161+
return userSession;
162+
}
163+
164+
protected UserSessionBean updateUserSession(UserSessionBean userSession){
165+
if(userSession == null){
166+
userSession = getNewUserSession();
167+
} else {
168+
UserAccount thisUser = this.getUser();
169+
long contextId = thisUser.getDefaultContext().getId();
170+
long userAccountid = thisUser.getId();
171+
userSession.update(userAccountid,contextId);
172+
}
173+
return userSession;
174+
}
175+
157176
/*
158177
protected Context getContext(UserSessionBean userSession){
159178
UserAccount thisUser = this.getUser();

src/main/java/org/woehlke/simpleworklist/domain/breadcrumb/BreadcrumbServiceImpl.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,20 @@ public Breadcrumb getBreadcrumbForShowOneProject(Project thisProject, Locale loc
6565
}
6666

6767
@Override
68-
public Breadcrumb getBreadcrumbForTaskstate(TaskState taskstate, Locale locale, UserSessionBean userSession) {
68+
public Breadcrumb getBreadcrumbForTaskstate(
69+
TaskState taskstate,
70+
Locale locale,
71+
UserSessionBean userSession
72+
) {
6973
log.debug("getBreadcrumbForTaskstate");
70-
Optional<Context> context = contextService.getContextFor(userSession);
71-
Breadcrumb breadcrumb = new Breadcrumb(locale, context.get());
74+
Optional<Context> contextResult = contextService.getContextFor(userSession);
75+
Context context;
76+
if(contextResult.isEmpty()){
77+
context = null;
78+
} else {
79+
context = contextResult.get();
80+
}
81+
Breadcrumb breadcrumb = new Breadcrumb(locale, context);
7282
String code = taskstate.getCode();
7383
String name = messageSource.getMessage(code,null,locale);
7484
breadcrumb.addTaskstate(name,taskstate.getUrl());

src/main/java/org/woehlke/simpleworklist/user/session/UserSessionBean.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,21 @@ public class UserSessionBean implements Serializable {
2727
private String lastSearchterm; //TODO: Make SearchRequest to Entity
2828

2929
public UserSessionBean(){
30-
lastSearchterm=""; //TODO: Make SearchRequest to Entity
31-
lastTaskState=TaskState.INBOX;
32-
lastProjectId=0L;
33-
lastContextId=0L;
34-
lastTaskId=0L;
35-
userAccountid=0L;
30+
this.lastSearchterm=""; //TODO: Make SearchRequest to Entity
31+
this.lastTaskState=TaskState.INBOX;
32+
this.lastProjectId=0L;
33+
this.lastContextId=0L;
34+
this.lastTaskId=0L;
35+
this.userAccountid=0L;
36+
}
37+
38+
public UserSessionBean(long userAccountid, long lastContextId){
39+
this.lastSearchterm=""; //TODO: Make SearchRequest to Entity
40+
this.lastTaskState=TaskState.INBOX;
41+
this.lastProjectId=0L;
42+
this.lastTaskId=0L;
43+
this.userAccountid=userAccountid;
44+
this.lastContextId=lastContextId;
3645
}
3746

3847
@Deprecated
@@ -45,4 +54,10 @@ public UserSessionBean(long contextId){
4554
userAccountid=0L;
4655
}
4756

57+
public void update(long userAccountid, long contextId) {
58+
this.userAccountid=userAccountid;
59+
if(this.lastContextId == 0L ){
60+
this.lastContextId=contextId;
61+
}
62+
}
4863
}

0 commit comments

Comments
 (0)