Skip to content

Commit 51d1053

Browse files
committed
work
1 parent 4712bce commit 51d1053

File tree

8 files changed

+162
-168
lines changed

8 files changed

+162
-168
lines changed
Lines changed: 95 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,198 +1,157 @@
11
package org.woehlke.java.simpleworklist.domain;
22

33
import org.springframework.ui.Model;
4-
import org.springframework.validation.BindingResult;
54
import org.springframework.web.bind.annotation.ModelAttribute;
65
import org.springframework.web.bind.annotation.SessionAttributes;
76
import org.woehlke.java.simpleworklist.domain.db.data.Project;
87
import org.woehlke.java.simpleworklist.domain.db.data.project.ProjectService;
98
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;
129
import org.woehlke.java.simpleworklist.domain.db.data.Context;
13-
import org.woehlke.java.simpleworklist.domain.db.data.Task;
1410
import org.woehlke.java.simpleworklist.domain.db.data.task.TaskService;
1511
import org.woehlke.java.simpleworklist.domain.db.data.task.TaskState;
1612
import org.woehlke.java.simpleworklist.domain.db.user.UserAccount;
1713
import org.woehlke.java.simpleworklist.domain.db.data.task.TaskEnergy;
1814
import org.woehlke.java.simpleworklist.domain.db.data.task.TaskTime;
1915
import org.woehlke.java.simpleworklist.domain.db.data.context.ContextService;
2016
import org.woehlke.java.simpleworklist.domain.db.user.chat.ChatMessageService;
21-
import org.woehlke.java.simpleworklist.domain.db.user.account.UserAccountService;
2217

2318
import org.springframework.beans.factory.annotation.Autowired;
24-
import org.woehlke.java.simpleworklist.domain.security.access.UserAuthorizationService;
2519
import org.woehlke.java.simpleworklist.domain.security.login.LoginSuccessService;
2620

2721
import javax.validation.constraints.NotNull;
28-
import java.util.ArrayList;
2922
import java.util.List;
3023
import java.util.Locale;
3124

3225
import static java.util.Locale.GERMAN;
33-
import static org.woehlke.java.simpleworklist.domain.db.data.task.TaskState.*;
3426

3527
/**
3628
* Created by tw on 14.02.16.
3729
*/
38-
@SessionAttributes({"userSession","locale"})
30+
@SessionAttributes({"userSession", "locale"})
3931
public abstract class AbstractController {
4032

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;
5135

52-
@Autowired
53-
protected ProjectService projectService;
54-
55-
/*
56-
@Autowired
57-
protected UserAccountService userAccountService;
58-
*/
5936
/*
60-
@Autowired
61-
protected UserAuthorizationService userAuthorizationService;
37+
@Autowired
38+
private TaskService taskService;
6239
*/
6340

64-
@Autowired
65-
protected ChatMessageService chatMessageService;
41+
@Autowired
42+
private ProjectService projectService;
6643

67-
@Autowired
68-
protected LoginSuccessService loginSuccessService;
44+
@Autowired
45+
private ChatMessageService chatMessageService;
6946

70-
/*
71-
@Autowired
72-
protected BreadcrumbService breadcrumbService;
73-
*/
47+
@Autowired
48+
private LoginSuccessService loginSuccessService;
7449

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-
}
8550

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+
}
9461

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+
}
10070

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+
}
10682

10783
@ModelAttribute("listTaskEnergy")
108-
public final List<TaskEnergy> getListTaskEnergy(){
84+
public final List<TaskEnergy> getListTaskEnergy() {
10985
return TaskEnergy.list();
11086
}
11187

11288
@ModelAttribute("listTaskTime")
113-
public final List<TaskTime> getListTaskTime(){
89+
public final List<TaskTime> getListTaskTime() {
11490
return TaskTime.list();
11591
}
11692

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+
}
13997

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;
143108
}
144-
145-
protected UserAccount getUser() {
146-
return this.loginSuccessService.retrieveCurrentUser();
109+
if (locale == GERMAN) {
110+
return context.getNameDe();
111+
} else {
112+
return context.getNameEn();
147113
}
114+
}
148115

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+
}
160120

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+
}
169124

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;
180132
}
133+
Context context = contextService.findByIdAndUserAccount(newContextId, thisUser);
134+
return context;
135+
}
181136

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+
}
182144

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);
195153
}
196-
*/
154+
return userSession;
155+
}
197156

198157
}

src/main/java/org/woehlke/java/simpleworklist/domain/ProjectIdController.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
import org.springframework.validation.ObjectError;
1212
import org.springframework.web.bind.annotation.*;
1313
import org.woehlke.java.simpleworklist.domain.db.data.Project;
14+
import org.woehlke.java.simpleworklist.domain.db.data.context.ContextService;
1415
import org.woehlke.java.simpleworklist.domain.db.data.project.ProjectControllerService;
1516
import org.woehlke.java.simpleworklist.domain.db.data.Context;
1617
import org.woehlke.java.simpleworklist.domain.db.data.Task;
18+
import org.woehlke.java.simpleworklist.domain.db.data.project.ProjectService;
19+
import org.woehlke.java.simpleworklist.domain.db.data.task.TaskService;
1720
import org.woehlke.java.simpleworklist.domain.db.user.UserAccount;
1821
import org.woehlke.java.simpleworklist.domain.meso.breadcrumb.Breadcrumb;
1922
import org.woehlke.java.simpleworklist.domain.meso.breadcrumb.BreadcrumbService;
@@ -37,14 +40,19 @@
3740
public class ProjectIdController extends AbstractController {
3841

3942
private final ProjectControllerService projectControllerService;
43+
private final ProjectService projectService;
4044
private final TaskMoveService taskMoveService;
41-
45+
private final TaskService taskService;
46+
private final ContextService contextService;
4247
private final BreadcrumbService breadcrumbService;
4348

4449
@Autowired
45-
public ProjectIdController(ProjectControllerService projectControllerService, TaskMoveService taskMoveService, BreadcrumbService breadcrumbService) {
50+
public ProjectIdController(ProjectControllerService projectControllerService, ProjectService projectService, TaskMoveService taskMoveService, TaskService taskService, ContextService contextService, BreadcrumbService breadcrumbService) {
4651
this.projectControllerService = projectControllerService;
52+
this.projectService = projectService;
4753
this.taskMoveService = taskMoveService;
54+
this.taskService = taskService;
55+
this.contextService = contextService;
4856
this.breadcrumbService = breadcrumbService;
4957
}
5058

@@ -64,8 +72,8 @@ public final String project(
6472
Project thisProject = null;
6573
Page<Task> taskPage = null;
6674
if (projectId != 0) {
67-
thisProject = projectService.findByProjectId(projectId);
68-
taskPage = taskService.findByProject(thisProject, pageable);
75+
thisProject = projectControllerService.findByProjectId(projectId);
76+
taskPage = projectControllerService.findByProject(thisProject, pageable);
6977
} else {
7078
thisProject = new Project();
7179
thisProject.setId(0L);

0 commit comments

Comments
 (0)