1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sourceforge.mystique.application;
22
23 import java.util.List;
24
25 import net.sourceforge.mystique.domain.entity.Component;
26 import net.sourceforge.mystique.domain.entity.Project;
27 import net.sourceforge.mystique.domain.repository.ComponentRepository;
28 import net.sourceforge.mystique.domain.repository.ProjectRepository;
29 import net.sourceforge.mystique.domain.repository.Repository;
30 import net.sourceforge.mystique.domain.repository.RepositoryException;
31
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Controller;
34 import org.springframework.ui.Model;
35 import org.springframework.web.bind.annotation.RequestMapping;
36 import org.springframework.web.bind.annotation.RequestParam;
37
38
39
40
41 @Controller
42 public class ComponentController {
43
44 @Autowired
45 private ProjectRepository projectRepository;
46
47 @Autowired
48 private ComponentRepository componentRepository;
49
50 @RequestMapping("/project/component/list.xhtml")
51 public String handleList(@RequestParam("projectId") Long projectId, Model model) throws RepositoryException {
52
53 Project project = projectRepository.findById(projectId);
54 List<Component> list = componentRepository.findByProject(project, 0, Repository.SMALL_RESULT);
55
56 model.addAttribute("project", project);
57 model.addAttribute("list", list);
58
59 return "project.component.list";
60
61 }
62
63 @RequestMapping("/project/component/remove.xhtml")
64
65 public String handleRemove(@RequestParam("componentId") Long componentId) throws RepositoryException {
66
67 Component component = componentRepository.findById(componentId);
68 Long projectId = component.getProject().getId();
69 componentRepository.remove(component);
70
71 return "redirect:list.xhtml?projectId=" + projectId;
72
73 }
74
75 }