Revize 69638d42
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 | ||
---|---|---|
2 | 2 |
|
3 | 3 |
|
4 | 4 |
import com.fasterxml.jackson.databind.ObjectMapper; |
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.Constants; |
|
5 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project; |
7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Iteration; |
|
6 | 8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Person; |
9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Phase; |
|
7 | 10 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService; |
8 | 11 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.PersonService; |
9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.PersonDto; |
|
10 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.PersonMergeRequest; |
|
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; |
|
11 | 16 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.PersonToDto; |
17 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.PhaseToDto; |
|
12 | 18 |
import org.springframework.beans.factory.annotation.Autowired; |
13 | 19 |
import org.springframework.http.HttpStatus; |
14 | 20 |
import org.springframework.http.ResponseEntity; |
15 | 21 |
import org.springframework.stereotype.Controller; |
16 |
import org.springframework.web.bind.annotation.PostMapping;
|
|
17 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
18 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
22 |
import org.springframework.ui.Model;
|
|
23 |
import org.springframework.web.bind.annotation.*;
|
|
24 |
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
19 | 25 |
|
20 |
import java.util.Collections; |
|
21 |
import java.util.Comparator; |
|
22 |
import java.util.List; |
|
23 |
import java.util.Map; |
|
26 |
import javax.servlet.http.HttpSession; |
|
27 |
import java.util.*; |
|
24 | 28 |
|
25 | 29 |
/** |
26 | 30 |
* This class contains all endpoints of management/persons |
... | ... | |
32 | 36 |
@Autowired |
33 | 37 |
private ProjectService projectService; |
34 | 38 |
|
39 |
@GetMapping("/segment-iteration-phase") |
|
40 |
public ResponseEntity<String> getIterationAndPhasesFromProject(@RequestParam Map<String, String> requestData) { |
|
41 |
long ProjectId = Long.parseLong(requestData.get("projectId").toString()); |
|
42 |
ObjectMapper objectMapper = new ObjectMapper(); |
|
43 |
|
|
44 |
Project project = projectService.getProjectById(ProjectId); |
|
45 |
|
|
46 |
if (project == null) { |
|
47 |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Project not found"); |
|
48 |
} |
|
49 |
|
|
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 |
|
|
56 |
|
|
57 |
Collections.sort(iterationDtos, Comparator.comparing(IterationDto::getName, String.CASE_INSENSITIVE_ORDER)); |
|
58 |
Collections.sort(phasesDtos, Comparator.comparing(PhaseDto::getName, String.CASE_INSENSITIVE_ORDER)); |
|
59 |
|
|
60 |
IterationAndPhasesDto iterationAndPhasesDto = new IterationAndPhasesToDto().convert(iterationDtos, phasesDtos); |
|
61 |
|
|
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"); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
35 | 71 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/IterationAndPhasesDto.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Iteration; |
|
4 |
import lombok.AllArgsConstructor; |
|
5 |
import lombok.Builder; |
|
6 |
import lombok.Data; |
|
7 |
import lombok.NoArgsConstructor; |
|
8 |
|
|
9 |
import java.util.List; |
|
10 |
|
|
11 |
@Data |
|
12 |
@Builder |
|
13 |
@NoArgsConstructor |
|
14 |
@AllArgsConstructor |
|
15 |
public class IterationAndPhasesDto { |
|
16 |
|
|
17 |
private List<IterationDto> iterationDtos; |
|
18 |
private List<PhaseDto> phaseDtos; |
|
19 |
|
|
20 |
public static IterationAndPhasesDtoBuilder builder() {return new IterationAndPhasesDtoBuilder();} |
|
21 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/IterationDto.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model; |
|
2 |
|
|
3 |
import lombok.AllArgsConstructor; |
|
4 |
import lombok.Builder; |
|
5 |
import lombok.Data; |
|
6 |
import lombok.NoArgsConstructor; |
|
7 |
|
|
8 |
@Data |
|
9 |
@Builder |
|
10 |
@NoArgsConstructor |
|
11 |
@AllArgsConstructor |
|
12 |
public class IterationDto { |
|
13 |
|
|
14 |
private long id; |
|
15 |
private String externalId; |
|
16 |
private String name; |
|
17 |
private String description; |
|
18 |
|
|
19 |
public static IterationDtoBuilder builder() {return new IterationDtoBuilder();} |
|
20 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/PhaseDto.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model; |
|
2 |
|
|
3 |
import lombok.AllArgsConstructor; |
|
4 |
import lombok.Builder; |
|
5 |
import lombok.Data; |
|
6 |
import lombok.NoArgsConstructor; |
|
7 |
|
|
8 |
@Data |
|
9 |
@Builder |
|
10 |
@NoArgsConstructor |
|
11 |
@AllArgsConstructor |
|
12 |
public class PhaseDto { |
|
13 |
|
|
14 |
private long id; |
|
15 |
private String externalId; |
|
16 |
private String name; |
|
17 |
private String description; |
|
18 |
|
|
19 |
public static PhaseDtoBuilder builder() {return new PhaseDtoBuilder();} |
|
20 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/IterationAndPhasesToDto.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IterationAndPhasesDto; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IterationDto; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.PhaseDto; |
|
6 |
|
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
public class IterationAndPhasesToDto { |
|
10 |
|
|
11 |
public IterationAndPhasesDto convert (List<IterationDto> iterationDto, List<PhaseDto> phaseDtos) { |
|
12 |
if (iterationDto == null && phaseDtos == null) { |
|
13 |
return null; |
|
14 |
} |
|
15 |
|
|
16 |
return IterationAndPhasesDto.builder() |
|
17 |
.iterationDtos(iterationDto) |
|
18 |
.phaseDtos(phaseDtos) |
|
19 |
.build(); |
|
20 |
} |
|
21 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/IterationToDto.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Iteration; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Person; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IterationDto; |
|
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.PersonDto; |
|
7 |
|
|
8 |
import java.util.ArrayList; |
|
9 |
import java.util.List; |
|
10 |
|
|
11 |
public class IterationToDto implements ClassToDto<Iteration, IterationDto> { |
|
12 |
|
|
13 |
@Override |
|
14 |
public IterationDto convert(Iteration source) { |
|
15 |
if (source == null) { |
|
16 |
return null; |
|
17 |
} |
|
18 |
|
|
19 |
return IterationDto.builder() |
|
20 |
.externalId(source.getExternalId()) |
|
21 |
.id(source.getId()) |
|
22 |
.name(source.getName()) |
|
23 |
.description(source.getDescription()) |
|
24 |
.build(); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public List<IterationDto> convert(List<Iteration> source) { |
|
29 |
if (source == null) { |
|
30 |
return null; |
|
31 |
} |
|
32 |
|
|
33 |
ArrayList<IterationDto> iterationDtos = new ArrayList<>(); |
|
34 |
|
|
35 |
for (Iteration it: source) { |
|
36 |
iterationDtos.add(this.convert(it)); |
|
37 |
} |
|
38 |
return iterationDtos; |
|
39 |
} |
|
40 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/PhaseToDto.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Iteration; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Phase; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IterationDto; |
|
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.PhaseDto; |
|
7 |
|
|
8 |
import java.util.ArrayList; |
|
9 |
import java.util.List; |
|
10 |
|
|
11 |
public class PhaseToDto implements ClassToDto<Phase, PhaseDto> { |
|
12 |
@Override |
|
13 |
public PhaseDto convert(Phase source) { |
|
14 |
if (source == null) { |
|
15 |
return null; |
|
16 |
} |
|
17 |
|
|
18 |
return PhaseDto.builder() |
|
19 |
.externalId(source.getExternalId()) |
|
20 |
.id(source.getId()) |
|
21 |
.name(source.getName()) |
|
22 |
.description(source.getDescription()) |
|
23 |
.build(); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public List<PhaseDto> convert(List<Phase> source) { |
|
28 |
if (source == null) { |
|
29 |
return null; |
|
30 |
} |
|
31 |
|
|
32 |
ArrayList<PhaseDto> phasesDtos = new ArrayList<>(); |
|
33 |
|
|
34 |
for (Phase ph: source) { |
|
35 |
phasesDtos.add(this.convert(ph)); |
|
36 |
} |
|
37 |
return phasesDtos; |
|
38 |
} |
|
39 |
} |
src/main/resources/application.properties | ||
---|---|---|
12 | 12 |
# mssql database connection: |
13 | 13 |
spring.second-datasource.jdbc-url=jdbc:sqlserver://localhost:1433;databaseName=authspade;encrypt=true;trustServerCertificate=true |
14 | 14 |
spring.second-datasource.username=test |
15 |
spring.second-datasource.password= |
|
15 |
spring.second-datasource.password=test
|
|
16 | 16 |
spring.second-datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver |
17 | 17 |
|
18 | 18 |
# admin account username and password: |
Také k dispozici: Unified diff
https://kivprogrammers.atlassian.net/browse/TSP2-50 poslání iterací a fází vybraného projektu