|
1 | 1 | package org.woehlke.java.simpleworklist.domain; |
2 | 2 |
|
3 | 3 | import org.springframework.ui.Model; |
4 | | -import org.springframework.validation.BindingResult; |
5 | 4 | import org.springframework.web.bind.annotation.ModelAttribute; |
6 | 5 | import org.springframework.web.bind.annotation.SessionAttributes; |
7 | 6 | import org.woehlke.java.simpleworklist.domain.db.data.Project; |
8 | 7 | import org.woehlke.java.simpleworklist.domain.db.data.project.ProjectService; |
9 | 8 | import org.woehlke.java.simpleworklist.domain.meso.session.UserSessionBean; |
10 | | -import org.woehlke.java.simpleworklist.domain.meso.breadcrumb.BreadcrumbService; |
11 | | -import org.woehlke.java.simpleworklist.config.SimpleworklistProperties; |
12 | 9 | import org.woehlke.java.simpleworklist.domain.db.data.Context; |
13 | | -import org.woehlke.java.simpleworklist.domain.db.data.Task; |
14 | 10 | import org.woehlke.java.simpleworklist.domain.db.data.task.TaskService; |
15 | 11 | import org.woehlke.java.simpleworklist.domain.db.data.task.TaskState; |
16 | 12 | import org.woehlke.java.simpleworklist.domain.db.user.UserAccount; |
17 | 13 | import org.woehlke.java.simpleworklist.domain.db.data.task.TaskEnergy; |
18 | 14 | import org.woehlke.java.simpleworklist.domain.db.data.task.TaskTime; |
19 | 15 | import org.woehlke.java.simpleworklist.domain.db.data.context.ContextService; |
20 | 16 | import org.woehlke.java.simpleworklist.domain.db.user.chat.ChatMessageService; |
21 | | -import org.woehlke.java.simpleworklist.domain.db.user.account.UserAccountService; |
22 | 17 |
|
23 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
24 | | -import org.woehlke.java.simpleworklist.domain.security.access.UserAuthorizationService; |
25 | 19 | import org.woehlke.java.simpleworklist.domain.security.login.LoginSuccessService; |
26 | 20 |
|
27 | 21 | import javax.validation.constraints.NotNull; |
28 | | -import java.util.ArrayList; |
29 | 22 | import java.util.List; |
30 | 23 | import java.util.Locale; |
31 | 24 |
|
32 | 25 | import static java.util.Locale.GERMAN; |
33 | | -import static org.woehlke.java.simpleworklist.domain.db.data.task.TaskState.*; |
34 | 26 |
|
35 | 27 | /** |
36 | 28 | * Created by tw on 14.02.16. |
37 | 29 | */ |
38 | | -@SessionAttributes({"userSession","locale"}) |
| 30 | +@SessionAttributes({"userSession", "locale"}) |
39 | 31 | public abstract class AbstractController { |
40 | 32 |
|
41 | | - /* |
42 | | - @Autowired |
43 | | - protected SimpleworklistProperties simpleworklistProperties; |
44 | | - */ |
45 | | - |
46 | | - @Autowired |
47 | | - protected ContextService contextService; |
48 | | - |
49 | | - @Autowired |
50 | | - protected TaskService taskService; |
| 33 | + @Autowired |
| 34 | + private ContextService contextService; |
51 | 35 |
|
52 | | - @Autowired |
53 | | - protected ProjectService projectService; |
54 | | - |
55 | | - /* |
56 | | - @Autowired |
57 | | - protected UserAccountService userAccountService; |
58 | | - */ |
59 | 36 | /* |
60 | | - @Autowired |
61 | | - protected UserAuthorizationService userAuthorizationService; |
| 37 | + @Autowired |
| 38 | + private TaskService taskService; |
62 | 39 | */ |
63 | 40 |
|
64 | | - @Autowired |
65 | | - protected ChatMessageService chatMessageService; |
| 41 | + @Autowired |
| 42 | + private ProjectService projectService; |
66 | 43 |
|
67 | | - @Autowired |
68 | | - protected LoginSuccessService loginSuccessService; |
| 44 | + @Autowired |
| 45 | + private ChatMessageService chatMessageService; |
69 | 46 |
|
70 | | - /* |
71 | | - @Autowired |
72 | | - protected BreadcrumbService breadcrumbService; |
73 | | - */ |
| 47 | + @Autowired |
| 48 | + private LoginSuccessService loginSuccessService; |
74 | 49 |
|
75 | | - @ModelAttribute("allProjects") |
76 | | - public final List<Project> getAllCategories( |
77 | | - @ModelAttribute("userSession") UserSessionBean userSession //, |
78 | | - // BindingResult result, //TODO: remove |
79 | | - // Model model //TODO: remove |
80 | | - ) { |
81 | | - userSession = updateUserSession(userSession); |
82 | | - Context context = this.getContext(userSession); |
83 | | - return projectService.findAllProjectsByContext(context); |
84 | | - } |
85 | 50 |
|
86 | | - @ModelAttribute("rootProjects") |
87 | | - public final List<Project> getRootCategories( |
88 | | - @ModelAttribute("userSession") UserSessionBean userSession |
89 | | - ) { |
90 | | - userSession = updateUserSession(userSession); |
91 | | - Context context = this.getContext(userSession); |
92 | | - return projectService.findRootProjectsByContext(context); |
93 | | - } |
| 51 | + @ModelAttribute("allProjects") |
| 52 | + public final List<Project> getAllProjects( |
| 53 | + @ModelAttribute("userSession") UserSessionBean userSession //, |
| 54 | + // BindingResult result, //TODO: remove |
| 55 | + // Model model //TODO: remove |
| 56 | + ) { |
| 57 | + userSession = updateUserSession(userSession); |
| 58 | + Context context = this.getContext(userSession); |
| 59 | + return projectService.findAllProjectsByContext(context); |
| 60 | + } |
94 | 61 |
|
95 | | - @ModelAttribute("numberOfNewIncomingMessages") |
96 | | - public final int getNumberOfNewIncomingMessages(){ |
97 | | - UserAccount user = this.getUser(); |
98 | | - return chatMessageService.getNumberOfNewIncomingMessagesForUser(user); |
99 | | - } |
| 62 | + @ModelAttribute("rootProjects") |
| 63 | + public final List<Project> getRootCategories( |
| 64 | + @ModelAttribute("userSession") UserSessionBean userSession |
| 65 | + ) { |
| 66 | + userSession = updateUserSession(userSession); |
| 67 | + Context context = this.getContext(userSession); |
| 68 | + return projectService.findRootProjectsByContext(context); |
| 69 | + } |
100 | 70 |
|
101 | | - @ModelAttribute("contexts") |
102 | | - public final List<Context> getContexts(){ |
103 | | - UserAccount user = this.getUser(); |
104 | | - return contextService.getAllForUser(user); |
105 | | - } |
| 71 | + @ModelAttribute("numberOfNewIncomingMessages") |
| 72 | + public final int getNumberOfNewIncomingMessages() { |
| 73 | + UserAccount user = this.getUser(); |
| 74 | + return chatMessageService.getNumberOfNewIncomingMessagesForUser(user); |
| 75 | + } |
| 76 | + |
| 77 | + @ModelAttribute("contexts") |
| 78 | + public final List<Context> getContexts() { |
| 79 | + UserAccount user = this.getUser(); |
| 80 | + return contextService.getAllForUser(user); |
| 81 | + } |
106 | 82 |
|
107 | 83 | @ModelAttribute("listTaskEnergy") |
108 | | - public final List<TaskEnergy> getListTaskEnergy(){ |
| 84 | + public final List<TaskEnergy> getListTaskEnergy() { |
109 | 85 | return TaskEnergy.list(); |
110 | 86 | } |
111 | 87 |
|
112 | 88 | @ModelAttribute("listTaskTime") |
113 | | - public final List<TaskTime> getListTaskTime(){ |
| 89 | + public final List<TaskTime> getListTaskTime() { |
114 | 90 | return TaskTime.list(); |
115 | 91 | } |
116 | 92 |
|
117 | | - @ModelAttribute("listTaskState") |
118 | | - public final List<TaskState> getTaskStates(){ |
119 | | - return TaskState.getLlist4Ui(); |
120 | | - } |
121 | | - |
122 | | - @ModelAttribute("context") |
123 | | - public final String getCurrentContext( |
124 | | - @ModelAttribute("userSession") UserSessionBean userSession, |
125 | | - Locale locale, |
126 | | - Model model |
127 | | - ){ |
128 | | - userSession = updateUserSession(userSession); |
129 | | - Context context = getContext(userSession); |
130 | | - if(locale == null){ |
131 | | - locale = Locale.ENGLISH; |
132 | | - } |
133 | | - if(locale == GERMAN){ |
134 | | - return context.getNameDe(); |
135 | | - } else { |
136 | | - return context.getNameEn(); |
137 | | - } |
138 | | - } |
| 93 | + @ModelAttribute("listTaskState") |
| 94 | + public final List<TaskState> getTaskStates() { |
| 95 | + return TaskState.getLlist4Ui(); |
| 96 | + } |
139 | 97 |
|
140 | | - @ModelAttribute("refreshMessages") |
141 | | - public final boolean refreshMessagePage(){ |
142 | | - return false; |
| 98 | + @ModelAttribute("context") |
| 99 | + public final String getCurrentContext( |
| 100 | + @ModelAttribute("userSession") UserSessionBean userSession, |
| 101 | + Locale locale//, |
| 102 | + //Model model |
| 103 | + ) { |
| 104 | + userSession = updateUserSession(userSession); |
| 105 | + Context context = getContext(userSession); |
| 106 | + if (locale == null) { |
| 107 | + locale = Locale.ENGLISH; |
143 | 108 | } |
144 | | - |
145 | | - protected UserAccount getUser() { |
146 | | - return this.loginSuccessService.retrieveCurrentUser(); |
| 109 | + if (locale == GERMAN) { |
| 110 | + return context.getNameDe(); |
| 111 | + } else { |
| 112 | + return context.getNameEn(); |
147 | 113 | } |
| 114 | + } |
148 | 115 |
|
149 | | - protected Context getContext(@NotNull final UserSessionBean userSession){ |
150 | | - UserAccount thisUser = this.getUser(); |
151 | | - long defaultContextId = thisUser.getDefaultContext().getId(); |
152 | | - long userSessionLastContextId = userSession.getLastContextId(); |
153 | | - long newContextId = userSessionLastContextId; |
154 | | - if(userSessionLastContextId == 0L){ |
155 | | - newContextId = defaultContextId; |
156 | | - } |
157 | | - Context context = contextService.findByIdAndUserAccount(newContextId, thisUser); |
158 | | - return context; |
159 | | - } |
| 116 | + @ModelAttribute("refreshMessages") |
| 117 | + public final boolean refreshMessagePage() { |
| 118 | + return false; |
| 119 | + } |
160 | 120 |
|
161 | | - @Deprecated |
162 | | - protected UserSessionBean getNewUserSession(){ |
163 | | - UserAccount thisUser = this.getUser(); |
164 | | - long userAccountid = thisUser.getId(); |
165 | | - long contextId = thisUser.getDefaultContext().getId(); |
166 | | - UserSessionBean userSession = new UserSessionBean(userAccountid,contextId); |
167 | | - return userSession; |
168 | | - } |
| 121 | + protected UserAccount getUser() { |
| 122 | + return this.loginSuccessService.retrieveCurrentUser(); |
| 123 | + } |
169 | 124 |
|
170 | | - protected UserSessionBean updateUserSession(UserSessionBean userSession){ |
171 | | - if(userSession == null){ |
172 | | - userSession = getNewUserSession(); |
173 | | - } else { |
174 | | - UserAccount thisUser = this.getUser(); |
175 | | - long contextId = thisUser.getDefaultContext().getId(); |
176 | | - long userAccountid = thisUser.getId(); |
177 | | - userSession.update(userAccountid,contextId); |
178 | | - } |
179 | | - return userSession; |
| 125 | + protected Context getContext(@NotNull final UserSessionBean userSession) { |
| 126 | + UserAccount thisUser = this.getUser(); |
| 127 | + long defaultContextId = thisUser.getDefaultContext().getId(); |
| 128 | + long userSessionLastContextId = userSession.getLastContextId(); |
| 129 | + long newContextId = userSessionLastContextId; |
| 130 | + if (userSessionLastContextId == 0L) { |
| 131 | + newContextId = defaultContextId; |
180 | 132 | } |
| 133 | + Context context = contextService.findByIdAndUserAccount(newContextId, thisUser); |
| 134 | + return context; |
| 135 | + } |
181 | 136 |
|
| 137 | + private UserSessionBean getNewUserSession() { |
| 138 | + UserAccount thisUser = this.getUser(); |
| 139 | + long userAccountid = thisUser.getId(); |
| 140 | + long contextId = thisUser.getDefaultContext().getId(); |
| 141 | + UserSessionBean userSession = new UserSessionBean(userAccountid, contextId); |
| 142 | + return userSession; |
| 143 | + } |
182 | 144 |
|
183 | | - /* |
184 | | - protected Context getContext(UserSessionBean userSession){ |
185 | | - UserAccount thisUser = this.getUser(); |
186 | | - if(userSession == null){ |
187 | | - userSession = new UserSessionBean(); |
188 | | - } |
189 | | - long defaultContextId = thisUser.getDefaultContext().getId(); |
190 | | - userSession.setLastContextId(defaultContextId); |
191 | | - Context context = contextService.findByIdAndUserAccount(userSession.getLastContextId(), thisUser); |
192 | | - userSession.setLastContextId(context.getId()); |
193 | | - userSession.setUserAccountid(thisUser.getId()); |
194 | | - return context; |
| 145 | + private UserSessionBean updateUserSession(UserSessionBean userSession) { |
| 146 | + if (userSession == null) { |
| 147 | + userSession = getNewUserSession(); |
| 148 | + } else { |
| 149 | + UserAccount thisUser = this.getUser(); |
| 150 | + long contextId = thisUser.getDefaultContext().getId(); |
| 151 | + long userAccountid = thisUser.getId(); |
| 152 | + userSession.update(userAccountid, contextId); |
195 | 153 | } |
196 | | - */ |
| 154 | + return userSession; |
| 155 | + } |
197 | 156 |
|
198 | 157 | } |
0 commit comments