|
1 | | -package org.woehlke.simpleworklist.control.common; |
2 | | - |
3 | | -import org.springframework.ui.Model; |
4 | | -import org.springframework.validation.BindingResult; |
5 | | -import org.springframework.web.bind.annotation.ModelAttribute; |
6 | | -import org.springframework.web.bind.annotation.SessionAttributes; |
7 | | -import org.woehlke.simpleworklist.config.ApplicationProperties; |
8 | | -import org.woehlke.simpleworklist.oodm.entities.Context; |
9 | | -import org.woehlke.simpleworklist.oodm.entities.Project; |
10 | | -import org.woehlke.simpleworklist.oodm.entities.UserAccount; |
11 | | -import org.woehlke.simpleworklist.oodm.enumerations.TaskEnergy; |
12 | | -import org.woehlke.simpleworklist.oodm.enumerations.TaskTime; |
13 | | -import org.woehlke.simpleworklist.oodm.services.ContextService; |
14 | | -import org.woehlke.simpleworklist.oodm.services.ProjectService; |
15 | | -import org.woehlke.simpleworklist.oodm.services.User2UserMessageService; |
16 | | -import org.woehlke.simpleworklist.oodm.services.UserAccountService; |
17 | | -import org.woehlke.simpleworklist.model.beans.UserSessionBean; |
18 | | -import org.woehlke.simpleworklist.model.services.*; |
19 | | - |
20 | | -import org.springframework.beans.factory.annotation.Autowired; |
21 | | -import java.util.List; |
22 | | -import java.util.Locale; |
23 | | - |
24 | | -/** |
25 | | - * Created by tw on 14.02.16. |
26 | | - */ |
27 | | -@SessionAttributes({"userSession","locale"}) |
28 | | -public abstract class AbstractController { |
29 | | - |
30 | | - @Autowired |
31 | | - protected ApplicationProperties applicationProperties; |
32 | | - |
33 | | - @Autowired |
34 | | - protected ProjectService projectService; |
35 | | - |
36 | | - @Autowired |
37 | | - protected UserAccountService userAccountService; |
38 | | - |
39 | | - @Autowired |
40 | | - protected UserAccountAccessService userAccountAccessService; |
41 | | - |
42 | | - @Autowired |
43 | | - protected User2UserMessageService user2UserMessageService; |
44 | | - |
45 | | - @Autowired |
46 | | - protected UserAccountLoginSuccessService userAccountLoginSuccessService; |
47 | | - |
48 | | - @Autowired |
49 | | - protected ContextService contextService; |
50 | | - |
51 | | - @Autowired |
52 | | - protected BreadcrumbService breadcrumbService; |
53 | | - |
54 | | - @ModelAttribute("allCategories") |
55 | | - public final List<Project> getAllCategories(@ModelAttribute("userSession") UserSessionBean userSession, |
56 | | - BindingResult result, Model model) { |
57 | | - Context context = this.getContext(userSession); |
58 | | - return projectService.findAllProjectsByContext(context); |
59 | | - } |
60 | | - |
61 | | - @ModelAttribute("rootCategories") |
62 | | - public final List<Project> getRootCategories( |
63 | | - @ModelAttribute("userSession") UserSessionBean userSession, |
64 | | - BindingResult result, Model model |
65 | | - ) { |
66 | | - Context context = this.getContext(userSession); |
67 | | - return projectService.findRootProjectsByContext(context); |
68 | | - } |
69 | | - |
70 | | - @ModelAttribute("numberOfNewIncomingMessages") |
71 | | - public final int getNumberOfNewIncomingMessages(){ |
72 | | - UserAccount user = this.getUser(); |
73 | | - return user2UserMessageService.getNumberOfNewIncomingMessagesForUser(user); |
74 | | - } |
75 | | - |
76 | | - @ModelAttribute("listTaskEnergy") |
77 | | - public final List<TaskEnergy> getListTaskEnergy(){ |
78 | | - return TaskEnergy.list(); |
79 | | - } |
80 | | - |
81 | | - @ModelAttribute("listTaskTime") |
82 | | - public final List<TaskTime> getListTaskTime(){ |
83 | | - return TaskTime.list(); |
84 | | - } |
85 | | - |
86 | | - @ModelAttribute("contexts") |
87 | | - public final List<Context> getContexts(){ |
88 | | - UserAccount user = this.getUser(); |
89 | | - return contextService.getAllForUser(user); |
90 | | - } |
91 | | - |
92 | | - @ModelAttribute("context") |
93 | | - public final String getCurrentArea(@ModelAttribute("userSession") UserSessionBean userSession, |
94 | | - Locale locale){ |
95 | | - Context context = this.getContext(userSession); |
96 | | - if(locale == Locale.GERMAN){ |
97 | | - return context.getNameDe(); |
98 | | - } else { |
99 | | - return context.getNameEn(); |
100 | | - } |
101 | | - } |
102 | | - |
103 | | - @ModelAttribute("refreshMessages") |
104 | | - public final boolean refreshMessagePage(){ |
105 | | - return false; |
106 | | - } |
107 | | - |
108 | | - protected UserAccount getUser(){ |
109 | | - return this.userAccountLoginSuccessService.retrieveCurrentUser(); |
110 | | - } |
111 | | - |
112 | | - protected Context getContext(UserSessionBean userSession){ |
113 | | - UserAccount thisUser = this.getUser(); |
114 | | - long defaultContextId = thisUser.getDefaultContext().getId(); |
115 | | - if(userSession == null){ |
116 | | - userSession = new UserSessionBean(defaultContextId); |
117 | | - } |
118 | | - long contextId = userSession.getContextId(); |
119 | | - if(contextId == 0){ |
120 | | - userSession.setContextId(defaultContextId); |
121 | | - } |
122 | | - return contextService.findByIdAndUserAccount(contextId, thisUser); |
123 | | - } |
124 | | - |
125 | | -} |
| 1 | +package org.woehlke.simpleworklist.common; |
| 2 | + |
| 3 | +import org.springframework.ui.Model; |
| 4 | +import org.springframework.validation.BindingResult; |
| 5 | +import org.springframework.web.bind.annotation.ModelAttribute; |
| 6 | +import org.springframework.web.bind.annotation.SessionAttributes; |
| 7 | +import org.woehlke.simpleworklist.config.ApplicationProperties; |
| 8 | +import org.woehlke.simpleworklist.oodm.entities.Context; |
| 9 | +import org.woehlke.simpleworklist.oodm.entities.Project; |
| 10 | +import org.woehlke.simpleworklist.oodm.entities.UserAccount; |
| 11 | +import org.woehlke.simpleworklist.oodm.enumerations.TaskEnergy; |
| 12 | +import org.woehlke.simpleworklist.oodm.enumerations.TaskTime; |
| 13 | +import org.woehlke.simpleworklist.oodm.services.ContextService; |
| 14 | +import org.woehlke.simpleworklist.oodm.services.ProjectService; |
| 15 | +import org.woehlke.simpleworklist.oodm.services.User2UserMessageService; |
| 16 | +import org.woehlke.simpleworklist.oodm.services.UserAccountService; |
| 17 | +import org.woehlke.simpleworklist.model.beans.UserSessionBean; |
| 18 | +import org.woehlke.simpleworklist.model.services.*; |
| 19 | + |
| 20 | +import org.springframework.beans.factory.annotation.Autowired; |
| 21 | +import java.util.List; |
| 22 | +import java.util.Locale; |
| 23 | + |
| 24 | +/** |
| 25 | + * Created by tw on 14.02.16. |
| 26 | + */ |
| 27 | +@SessionAttributes({"userSession","locale"}) |
| 28 | +public abstract class AbstractController { |
| 29 | + |
| 30 | + @Autowired |
| 31 | + protected ApplicationProperties applicationProperties; |
| 32 | + |
| 33 | + @Autowired |
| 34 | + protected ProjectService projectService; |
| 35 | + |
| 36 | + @Autowired |
| 37 | + protected UserAccountService userAccountService; |
| 38 | + |
| 39 | + @Autowired |
| 40 | + protected UserAccountAccessService userAccountAccessService; |
| 41 | + |
| 42 | + @Autowired |
| 43 | + protected User2UserMessageService user2UserMessageService; |
| 44 | + |
| 45 | + @Autowired |
| 46 | + protected UserAccountLoginSuccessService userAccountLoginSuccessService; |
| 47 | + |
| 48 | + @Autowired |
| 49 | + protected ContextService contextService; |
| 50 | + |
| 51 | + @Autowired |
| 52 | + protected BreadcrumbService breadcrumbService; |
| 53 | + |
| 54 | + @ModelAttribute("allCategories") |
| 55 | + public final List<Project> getAllCategories(@ModelAttribute("userSession") UserSessionBean userSession, |
| 56 | + BindingResult result, Model model) { |
| 57 | + Context context = this.getContext(userSession); |
| 58 | + return projectService.findAllProjectsByContext(context); |
| 59 | + } |
| 60 | + |
| 61 | + @ModelAttribute("rootCategories") |
| 62 | + public final List<Project> getRootCategories( |
| 63 | + @ModelAttribute("userSession") UserSessionBean userSession, |
| 64 | + BindingResult result, Model model |
| 65 | + ) { |
| 66 | + Context context = this.getContext(userSession); |
| 67 | + return projectService.findRootProjectsByContext(context); |
| 68 | + } |
| 69 | + |
| 70 | + @ModelAttribute("numberOfNewIncomingMessages") |
| 71 | + public final int getNumberOfNewIncomingMessages(){ |
| 72 | + UserAccount user = this.getUser(); |
| 73 | + return user2UserMessageService.getNumberOfNewIncomingMessagesForUser(user); |
| 74 | + } |
| 75 | + |
| 76 | + @ModelAttribute("listTaskEnergy") |
| 77 | + public final List<TaskEnergy> getListTaskEnergy(){ |
| 78 | + return TaskEnergy.list(); |
| 79 | + } |
| 80 | + |
| 81 | + @ModelAttribute("listTaskTime") |
| 82 | + public final List<TaskTime> getListTaskTime(){ |
| 83 | + return TaskTime.list(); |
| 84 | + } |
| 85 | + |
| 86 | + @ModelAttribute("contexts") |
| 87 | + public final List<Context> getContexts(){ |
| 88 | + UserAccount user = this.getUser(); |
| 89 | + return contextService.getAllForUser(user); |
| 90 | + } |
| 91 | + |
| 92 | + @ModelAttribute("context") |
| 93 | + public final String getCurrentArea(@ModelAttribute("userSession") UserSessionBean userSession, |
| 94 | + Locale locale){ |
| 95 | + Context context = this.getContext(userSession); |
| 96 | + if(locale == Locale.GERMAN){ |
| 97 | + return context.getNameDe(); |
| 98 | + } else { |
| 99 | + return context.getNameEn(); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + @ModelAttribute("refreshMessages") |
| 104 | + public final boolean refreshMessagePage(){ |
| 105 | + return false; |
| 106 | + } |
| 107 | + |
| 108 | + protected UserAccount getUser(){ |
| 109 | + return this.userAccountLoginSuccessService.retrieveCurrentUser(); |
| 110 | + } |
| 111 | + |
| 112 | + protected Context getContext(UserSessionBean userSession){ |
| 113 | + UserAccount thisUser = this.getUser(); |
| 114 | + long defaultContextId = thisUser.getDefaultContext().getId(); |
| 115 | + if(userSession == null){ |
| 116 | + userSession = new UserSessionBean(defaultContextId); |
| 117 | + } |
| 118 | + long contextId = userSession.getContextId(); |
| 119 | + if(contextId == 0){ |
| 120 | + userSession.setContextId(defaultContextId); |
| 121 | + } |
| 122 | + return contextService.findByIdAndUserAccount(contextId, thisUser); |
| 123 | + } |
| 124 | + |
| 125 | +} |
0 commit comments