Skip to content

Commit 8b15a95

Browse files
committed
bugfixing
1 parent 33ef51d commit 8b15a95

File tree

7 files changed

+279
-233
lines changed

7 files changed

+279
-233
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,14 @@
4040
public class ProjectIdController extends AbstractController {
4141

4242
private final ProjectControllerService projectControllerService;
43-
private final ProjectService projectService;
4443
private final TaskMoveService taskMoveService;
4544
private final TaskService taskService;
4645
private final ContextService contextService;
4746
private final BreadcrumbService breadcrumbService;
4847

4948
@Autowired
50-
public ProjectIdController(ProjectControllerService projectControllerService, ProjectService projectService, TaskMoveService taskMoveService, TaskService taskService, ContextService contextService, BreadcrumbService breadcrumbService) {
49+
public ProjectIdController(ProjectControllerService projectControllerService, TaskMoveService taskMoveService, TaskService taskService, ContextService contextService, BreadcrumbService breadcrumbService) {
5150
this.projectControllerService = projectControllerService;
52-
this.projectService = projectService;
5351
this.taskMoveService = taskMoveService;
5452
this.taskService = taskService;
5553
this.contextService = contextService;
@@ -171,24 +169,24 @@ public final String projectEditPost(
171169
for (ObjectError e : result.getAllErrors()) {
172170
log.info(e.toString());
173171
}
174-
thisProject = projectService.findByProjectId(projectId);
172+
thisProject = projectControllerService.findByProjectId(projectId);
175173
Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShoProjectId(thisProject, locale, userSession);
176174
model.addAttribute("breadcrumb", breadcrumb);
177175
model.addAttribute("userSession", userSession);
178176
return "project/id/edit";
179177
} else {
180-
thisProject = projectService.findByProjectId(project.getId());
178+
thisProject = projectControllerService.findByProjectId(project.getId());
181179
thisProject.setName(project.getName());
182180
thisProject.setDescription(project.getDescription());
183181
Context newContext = project.getContext();
184182
boolean contextChanged = (newContext.getId().longValue() != thisProject.getContext().getId().longValue());
185183
if (contextChanged) {
186184
long newContextId = newContext.getId();
187185
newContext = contextService.findByIdAndUserAccount(newContextId, thisUser);
188-
thisProject = projectService.moveProjectToAnotherContext(thisProject, newContext);
186+
thisProject = projectControllerService.moveProjectToAnotherContext(thisProject, newContext);
189187
userSession.setLastContextId(newContextId);
190188
} else {
191-
thisProject = projectService.update(thisProject);
189+
thisProject = projectControllerService.update(thisProject);
192190
}
193191
userSession.setLastProjectId(thisProject.getId());
194192
model.addAttribute("userSession", userSession);
@@ -210,7 +208,7 @@ public final String projectDeleteGet(
210208
boolean hasNoChildren = project.hasNoChildren();
211209
boolean delete = hasNoData && hasNoChildren;
212210
if (delete) {
213-
Project parent = projectService.delete(project);
211+
Project parent = projectControllerService.delete(project);
214212
//TODO: message to message_properties
215213
String message = "Project is deleted. You see its parent project now.";
216214
//TODO: message to UserSessionBean userSession
@@ -260,8 +258,8 @@ public final String projectMoveToProjectGet(
260258
) {
261259
userSession.setLastProjectId(thisProject.getId());
262260
model.addAttribute("userSession", userSession);
263-
Project targetProject = projectService.findByProjectId(targetProjectId);
264-
thisProject = projectService.moveProjectToAnotherProject(thisProject, targetProject);
261+
Project targetProject = projectControllerService.findByProjectId(targetProjectId);
262+
thisProject = projectControllerService.moveProjectToAnotherProject(thisProject, targetProject);
265263
model.addAttribute("userSession", userSession);
266264
model.addAttribute("taskstateType", PROJECTS.getSlug());
267265
model.addAttribute("dataPage", true);

src/main/java/org/woehlke/java/simpleworklist/domain/db/data/project/ProjectService.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@
44
import org.springframework.data.domain.Pageable;
55
import org.woehlke.java.simpleworklist.domain.db.data.Context;
66
import org.woehlke.java.simpleworklist.domain.db.data.Project;
7+
import org.woehlke.java.simpleworklist.domain.db.data.Task;
78

89
import java.util.List;
910

1011
public interface ProjectService {
1112

1213
Project add(Project project);
1314
Project update(Project project);
14-
Project delete(Project project);
15+
void delete(Project project);
16+
17+
18+
List<Task> findByProject(Project thisProject);
1519

1620
List<Project> findRootProjectsByContext(Context context);
1721
Page<Project> findRootProjectsByContext(Context context, Pageable pageRequest);
1822

1923
List<Project> findAllProjectsByContext(Context context);
2024
Page<Project> findAllProjectsByContext(Context context, Pageable pageRequest);
2125

22-
Project moveProjectToAnotherProject(Project thisProject, Project targetProject);
23-
Project moveProjectToAnotherContext(Project thisProject, Context newContext);
24-
2526
Project getReferenceById(long projectId);
2627
Project findByProjectId(long projectId);
28+
29+
30+
List<Project> getAllChildrenOfProject(Project thisProject);
2731
}

src/main/java/org/woehlke/java/simpleworklist/domain/db/data/project/ProjectServiceImpl.java

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -86,73 +86,33 @@ public Project update(@NotNull Project entity) {
8686

8787
@Override
8888
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false)
89-
public Project delete(@NotNull Project thisProject) {
89+
public void delete(@NotNull Project thisProject) {
9090
log.info("delete");
91-
Project oldParent = thisProject.getParent();
92-
if (oldParent != null) {
93-
oldParent.getChildren().remove(thisProject);
94-
projectRepository.saveAndFlush(oldParent);
95-
}
9691
projectRepository.delete(thisProject);
97-
return oldParent;
9892
}
9993

100-
@Override
101-
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false)
102-
public Project moveProjectToAnotherContext(@NotNull Project thisProject, @NotNull Context newContext) {
103-
log.info("----------------------------------------------------");
104-
log.info("moveProjectToAnotherContext: Project: "+ thisProject.toString());
105-
log.info("----------------------------------------------------");
106-
log.info("moveProjectToAnotherContext: newContext: "+ newContext.toString());
107-
log.info("----------------------------------------------------");
108-
thisProject.setParent(null);
109-
thisProject = projectRepository.saveAndFlush(thisProject);
110-
//TODO: remove Recursion, remove unbounded Recursion and List instead of Page.
111-
List<Project> listProject = getAllChildrenOfProject(thisProject);
112-
for(Project childProject : listProject){
113-
List<Task> tasksOfChildProject = taskRepository.findByProject(childProject);
114-
for(Task task:tasksOfChildProject){
115-
task.setContext(newContext);
116-
}
117-
childProject.setContext(newContext);
118-
taskRepository.saveAll(tasksOfChildProject);
119-
projectRepository.saveAndFlush(childProject);
120-
}
121-
return thisProject;
122-
}
94+
@Override
95+
public List<Task> findByProject(Project thisProject) {
96+
return taskRepository.findByProject(thisProject);
97+
}
98+
12399

124100
@Override
125101
public Project getReferenceById(long projectId) {
126102
return projectRepository.getReferenceById(projectId);
127103
}
128104

129-
//TODO: remove Recursion, remove unbounded Recursion and List instead of Page.
130-
@Deprecated
131-
private List<Project> getAllChildrenOfProject(@NotNull Project thisProject) {
105+
106+
@Override
107+
public List<Project> getAllChildrenOfProject(@NotNull Project thisProject) {
132108
log.info("getAllChildrenOfProject");
133109
List<Project> childrenOfProject = new ArrayList<>();
134110
childrenOfProject.add(thisProject);
135111
for(Project p : thisProject.getChildren()){
136-
//TODO: remove Recursion, remove unbounded Recursion and List instead of Page.
137112
List<Project> getNextGeneration = getAllChildrenOfProject(p);
138113
childrenOfProject.addAll(getNextGeneration);
139114
}
140115
return childrenOfProject;
141116
}
142117

143-
@Override
144-
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false)
145-
public Project moveProjectToAnotherProject(
146-
@NotNull Project thisProject,
147-
@NotNull Project targetProject
148-
) {
149-
log.info("moveProjectToAnotherProject");
150-
Project oldParent = thisProject.getParent();
151-
if (oldParent != null) {
152-
oldParent.getChildren().remove(thisProject);
153-
projectRepository.saveAndFlush(oldParent);
154-
}
155-
thisProject.setParent(targetProject);
156-
return projectRepository.saveAndFlush(thisProject);
157-
}
158118
}

src/main/java/org/woehlke/java/simpleworklist/domain/db/data/task/TaskService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public interface TaskService {
2323
List<Task> findByTaskStateTrash(Context context);
2424
List<Task> findByTaskStateDeleted(Context context);
2525
List<Task> findByTaskStateProjects(Context context);
26+
List<Task> findByProjectId(Project thisProject);
2627

2728
Page<Task> findByTaskStateInbox(Context context, Pageable request);
2829
Page<Task> findByTaskStateToday(Context context, Pageable request);

src/main/java/org/woehlke/java/simpleworklist/domain/db/data/task/TaskServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ public List<Task> findByTaskStateProjects(Context context) {
142142
return taskRepository.findByTaskStateProjects(context);
143143
}
144144

145+
@Override
146+
public List<Task> findByProjectId(Project thisProject) {
147+
return taskRepository.findByProject(thisProject);
148+
}
149+
145150
@Override
146151
public Page<Task> findByTaskStateInbox(Context context, Pageable request) {
147152
return taskRepository.findByTaskStateInbox(context, request);

src/main/java/org/woehlke/java/simpleworklist/domain/meso/project/ProjectControllerService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.woehlke.java.simpleworklist.domain.db.data.Task;
1111
import org.woehlke.java.simpleworklist.domain.db.user.UserAccount;
1212

13+
import java.util.List;
1314
import java.util.Locale;
1415

1516
public interface ProjectControllerService {
@@ -54,10 +55,17 @@ Project getProject(
5455
UserSessionBean userSession
5556
);
5657

58+
Project add(Project project);
59+
Project update(Project project);
60+
Project delete(Project project);
61+
5762
void moveTaskToTaskAndChangeTaskOrderInProjectId(Task sourceTask, Task destinationTask);
5863
void moveTaskToTaskAndChangeTaskOrderInProjectRoot(Task sourceTask, Task destinationTask);
5964

6065
Project findByProjectId(long projectId);
6166
Page<Task> findByProject(Project thisProject, Pageable pageable);
67+
List<Task> findByProject(Project thisProject);
6268

69+
Project moveProjectToAnotherProject(Project thisProject, Project targetProject);
70+
Project moveProjectToAnotherContext(Project thisProject, Context newContext);
6371
}

0 commit comments

Comments
 (0)