Revize cf25eed3
Přidáno uživatelem Václav Hrabík před více než 1 rok
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/IterationAndPhasesController.java | ||
---|---|---|
1 | 1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller.management; |
2 | 2 |
|
3 | 3 |
|
4 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.Constants; |
|
6 | 4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project; |
7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Iteration; |
|
8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Person; |
|
9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Phase; |
|
10 | 5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService; |
11 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.PersonService; |
|
12 |
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils; |
|
13 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.*; |
|
14 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.IterationAndPhasesToDto; |
|
15 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.IterationToDto; |
|
16 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.PersonToDto; |
|
17 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.PhaseToDto; |
|
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.managment.IterationsAndPhasesService; |
|
18 | 7 |
import org.springframework.beans.factory.annotation.Autowired; |
19 | 8 |
import org.springframework.http.HttpStatus; |
20 | 9 |
import org.springframework.http.ResponseEntity; |
21 | 10 |
import org.springframework.stereotype.Controller; |
22 |
import org.springframework.ui.Model; |
|
23 | 11 |
import org.springframework.web.bind.annotation.*; |
24 |
import org.springframework.web.servlet.mvc.support.RedirectAttributes; |
|
25 | 12 |
|
26 |
import javax.servlet.http.HttpSession; |
|
27 | 13 |
import java.util.*; |
28 | 14 |
|
29 | 15 |
/** |
... | ... | |
33 | 19 |
@RequestMapping("v2/management") |
34 | 20 |
public class IterationAndPhasesController { |
35 | 21 |
|
22 |
@Autowired |
|
23 |
private IterationsAndPhasesService iterationsAndPhasesService; |
|
24 |
|
|
36 | 25 |
@Autowired |
37 | 26 |
private ProjectService projectService; |
38 | 27 |
|
39 | 28 |
@GetMapping("/segment-iteration-phase") |
40 | 29 |
public ResponseEntity<String> getIterationAndPhasesFromProject(@RequestParam Map<String, String> requestData) { |
41 | 30 |
long ProjectId = Long.parseLong(requestData.get("projectId").toString()); |
42 |
ObjectMapper objectMapper = new ObjectMapper(); |
|
43 | 31 |
|
44 | 32 |
Project project = projectService.getProjectById(ProjectId); |
45 | 33 |
|
... | ... | |
47 | 35 |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Project not found"); |
48 | 36 |
} |
49 | 37 |
|
50 |
List<Iteration> iterations = project.getIterations(); |
|
51 |
List<Phase> phases = project.getPhases(); |
|
52 |
|
|
53 |
List<IterationDto> iterationDtos = new IterationToDto().convert(iterations); |
|
54 |
List<PhaseDto> phasesDtos = new PhaseToDto().convert(phases); |
|
55 |
|
|
38 |
return iterationsAndPhasesService.getIterationAndPhases(project); |
|
39 |
} |
|
56 | 40 |
|
57 |
Collections.sort(iterationDtos, Comparator.comparing(IterationDto::getName, String.CASE_INSENSITIVE_ORDER)); |
|
58 |
Collections.sort(phasesDtos, Comparator.comparing(PhaseDto::getName, String.CASE_INSENSITIVE_ORDER)); |
|
41 |
@PostMapping("/changeIteration") |
|
42 |
public ResponseEntity<String> changeIteration(@RequestBody Map<String, String[]> requestData) { |
|
43 |
if (requestData.get("Ids").length == 0) { |
|
44 |
return ResponseEntity.status(HttpStatus.NO_CONTENT).body("No Iterations send"); |
|
45 |
} |
|
59 | 46 |
|
60 |
IterationAndPhasesDto iterationAndPhasesDto = new IterationAndPhasesToDto().convert(iterationDtos, phasesDtos); |
|
47 |
return iterationsAndPhasesService.changeToPhase(requestData.get("Ids")); |
|
48 |
} |
|
61 | 49 |
|
62 |
try { |
|
63 |
String json = objectMapper.writeValueAsString(iterationAndPhasesDto); |
|
64 |
return ResponseEntity.status((iterations != null && phases != null) ? HttpStatus.OK : HttpStatus.NO_CONTENT).body(json); |
|
65 |
} catch (Exception e) { |
|
66 |
e.printStackTrace(); |
|
67 |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to serialize data to JSON"); |
|
50 |
@PostMapping("/changePhase") |
|
51 |
public ResponseEntity<String> changePhase(@RequestBody Map<String, String[]> requestData) { |
|
52 |
if (requestData.get("Ids").length == 0) { |
|
53 |
return ResponseEntity.status(HttpStatus.NO_CONTENT).body("No Phases send"); |
|
68 | 54 |
} |
55 |
|
|
56 |
return iterationsAndPhasesService.changeToIteration(requestData.get("Ids")); |
|
69 | 57 |
} |
70 | 58 |
|
71 | 59 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/managment/IterationsAndPhasesService.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.managment; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project; |
|
4 |
import org.springframework.http.ResponseEntity; |
|
5 |
|
|
6 |
public interface IterationsAndPhasesService { |
|
7 |
|
|
8 |
public ResponseEntity<String> getIterationAndPhases(Project project); |
|
9 |
|
|
10 |
public ResponseEntity<String> changeToPhase(String[] iterationsIds); |
|
11 |
|
|
12 |
public ResponseEntity<String> changeToIteration(String[] phasesIds); |
|
13 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/managment/IterationsAndPhasesServiceImpl.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.managment; |
|
2 |
|
|
3 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Iteration; |
|
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Phase; |
|
7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IterationAndPhasesDto; |
|
8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IterationDto; |
|
9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.PhaseDto; |
|
10 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.IterationAndPhasesToDto; |
|
11 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.IterationToDto; |
|
12 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.PhaseToDto; |
|
13 |
import org.springframework.http.HttpStatus; |
|
14 |
import org.springframework.http.ResponseEntity; |
|
15 |
import org.springframework.stereotype.Service; |
|
16 |
|
|
17 |
import java.util.Collections; |
|
18 |
import java.util.Comparator; |
|
19 |
import java.util.List; |
|
20 |
|
|
21 |
@Service |
|
22 |
public class IterationsAndPhasesServiceImpl implements IterationsAndPhasesService { |
|
23 |
|
|
24 |
@Override |
|
25 |
public ResponseEntity<String> getIterationAndPhases(Project project) { |
|
26 |
ObjectMapper objectMapper = new ObjectMapper(); |
|
27 |
|
|
28 |
List<Iteration> iterations = project.getIterations(); |
|
29 |
List<Phase> phases = project.getPhases(); |
|
30 |
|
|
31 |
List<IterationDto> iterationDtos = new IterationToDto().convert(iterations); |
|
32 |
List<PhaseDto> phasesDtos = new PhaseToDto().convert(phases); |
|
33 |
|
|
34 |
|
|
35 |
Collections.sort(iterationDtos, Comparator.comparing(IterationDto::getName, String.CASE_INSENSITIVE_ORDER)); |
|
36 |
Collections.sort(phasesDtos, Comparator.comparing(PhaseDto::getName, String.CASE_INSENSITIVE_ORDER)); |
|
37 |
|
|
38 |
IterationAndPhasesDto iterationAndPhasesDto = new IterationAndPhasesToDto().convert(iterationDtos, phasesDtos); |
|
39 |
|
|
40 |
try { |
|
41 |
String json = objectMapper.writeValueAsString(iterationAndPhasesDto); |
|
42 |
return ResponseEntity.status((iterations != null && phases != null) ? HttpStatus.OK : HttpStatus.NO_CONTENT).body(json); |
|
43 |
} catch (Exception e) { |
|
44 |
e.printStackTrace(); |
|
45 |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to serialize data to JSON"); |
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public ResponseEntity<String> changeToPhase(String[] iterationsIds) { |
|
51 |
return null; |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public ResponseEntity<String> changeToIteration(String[] phasesIds) { |
|
56 |
return null; |
|
57 |
} |
|
58 |
|
|
59 |
} |
Také k dispozici: Unified diff
https://kivprogrammers.atlassian.net/browse/TSP2-50 přijímání dat z frontendu a příprava endpointů