Revize 0dda3567
Přidáno uživatelem stepanekp před více než 1 rok
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/PersonController.java | ||
---|---|---|
25 | 25 |
/** |
26 | 26 |
* This class contains all endpoints of person.html |
27 | 27 |
*/ |
28 |
@Controller |
|
28 |
//@Controller
|
|
29 | 29 |
public class PersonController { |
30 | 30 |
|
31 | 31 |
private final Logger LOGGER = LoggerFactory.getLogger(PersonController.class); |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/PersonController.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller.management; |
|
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.Person; |
|
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService; |
|
7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.PersonDto; |
|
8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.PersonToDto; |
|
9 |
import org.springframework.beans.factory.annotation.Autowired; |
|
10 |
import org.springframework.http.HttpStatus; |
|
11 |
import org.springframework.http.ResponseEntity; |
|
12 |
import org.springframework.stereotype.Controller; |
|
13 |
import org.springframework.web.bind.annotation.PostMapping; |
|
14 |
import org.springframework.web.bind.annotation.RequestBody; |
|
15 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
16 |
|
|
17 |
import java.util.Collections; |
|
18 |
import java.util.Comparator; |
|
19 |
import java.util.List; |
|
20 |
import java.util.Map; |
|
21 |
|
|
22 |
/** |
|
23 |
* This class contains all endpoints of management/persons |
|
24 |
*/ |
|
25 |
@Controller |
|
26 |
@RequestMapping("v2/management") |
|
27 |
public class PersonController { |
|
28 |
|
|
29 |
@Autowired |
|
30 |
private ProjectService projectService; |
|
31 |
|
|
32 |
@PostMapping("/personsFromProject") |
|
33 |
public ResponseEntity<String> getPersonsFromProject(@RequestBody Map<String, String> requestData) { |
|
34 |
long ProjectId = Long.parseLong(requestData.get("projectId").toString()); |
|
35 |
ObjectMapper objectMapper = new ObjectMapper(); |
|
36 |
|
|
37 |
Project project = projectService.getProjectById(ProjectId); |
|
38 |
|
|
39 |
if (project == null) { |
|
40 |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Project not found"); |
|
41 |
} |
|
42 |
List<Person> persons = project.getPeople(); |
|
43 |
List<PersonDto> personDtos = new PersonToDto().convert(persons); |
|
44 |
Collections.sort(personDtos, Comparator.comparing(PersonDto::getName, String.CASE_INSENSITIVE_ORDER)); |
|
45 |
|
|
46 |
try { |
|
47 |
String json = objectMapper.writeValueAsString(personDtos); |
|
48 |
return ResponseEntity.status(persons != null ? HttpStatus.OK : HttpStatus.NO_CONTENT).body(json); |
|
49 |
} catch (Exception e) { |
|
50 |
e.printStackTrace(); |
|
51 |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to serialize data to JSON"); |
|
52 |
} |
|
53 |
} |
|
54 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/ProjectController.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
|
23 | 23 |
/** |
24 |
* This class contains all endpoints of projects.html
|
|
24 |
* This class contains all endpoints connected to Projects
|
|
25 | 25 |
*/ |
26 | 26 |
@Controller |
27 | 27 |
@RequestMapping("v2/management") |
... | ... | |
30 | 30 |
@Autowired |
31 | 31 |
private ProjectService projectService; |
32 | 32 |
|
33 |
@GetMapping("/projects") |
|
34 |
public ResponseEntity<String> getProjectsData() { |
|
33 |
@GetMapping("/projectsList") |
|
34 |
public ResponseEntity<String> getProjectsList() { |
|
35 |
ProjectToDto projectToDto = new ProjectToDto(); |
|
36 |
List<ProjectDto> projects = projectToDto.convert(projectService.getAllProjects()); |
|
37 |
return ResponseEntity.status(projects.size() > 0 ? HttpStatus.OK : HttpStatus.NO_CONTENT).body(new Gson().toJson(projects)); |
|
38 |
} |
|
39 |
|
|
40 |
@GetMapping("/projectsHierarchy") |
|
41 |
public ResponseEntity<String> getProjectsHierarchy() { |
|
35 | 42 |
ProjectToDto projectToDto = new ProjectToDto(); |
36 | 43 |
List<Node> parents = new ArrayList<>(); |
37 | 44 |
List<ProjectDto> parentProjects = projectToDto.convert(projectService.getParentProjects()); |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/IdentityDto.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 IdentityDto { |
|
13 |
|
|
14 |
private Long id; |
|
15 |
private String name; |
|
16 |
|
|
17 |
private String description; |
|
18 |
|
|
19 |
private String email; |
|
20 |
|
|
21 |
|
|
22 |
public static IdentityDtoBuilder builder() {return new IdentityDtoBuilder();} |
|
23 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/PersonDto.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 |
import java.util.List; |
|
9 |
|
|
10 |
@Data |
|
11 |
@Builder |
|
12 |
@NoArgsConstructor |
|
13 |
@AllArgsConstructor |
|
14 |
public class PersonDto { |
|
15 |
|
|
16 |
private Long id; |
|
17 |
private String name; |
|
18 |
|
|
19 |
private List<IdentityDto> identities; |
|
20 |
|
|
21 |
public static PersonDtoBuilder builder() {return new PersonDtoBuilder();} |
|
22 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/IdentityToDto.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters; |
|
2 |
|
|
3 |
|
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Identity; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IdentityDto; |
|
6 |
|
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.List; |
|
9 |
|
|
10 |
public class IdentityToDto implements ClassToDto<Identity, IdentityDto> { |
|
11 |
|
|
12 |
@Override |
|
13 |
public IdentityDto convert(Identity source) { |
|
14 |
if (source == null) { |
|
15 |
return null; |
|
16 |
} |
|
17 |
|
|
18 |
return IdentityDto.builder() |
|
19 |
.id(source.getId()) |
|
20 |
.name(source.getName()) |
|
21 |
.description(source.getDescription()) |
|
22 |
.email(source.getEmail()) |
|
23 |
.build(); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public List<IdentityDto> convert(List<Identity> source) { |
|
28 |
List<IdentityDto> convertedList = new ArrayList<>(); |
|
29 |
|
|
30 |
if(source == null){ |
|
31 |
return convertedList; |
|
32 |
} |
|
33 |
source.stream().forEach(sourceItem->convertedList.add(this.convert(sourceItem))); |
|
34 |
return convertedList; |
|
35 |
} |
|
36 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/PersonToDto.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Person; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IdentityDto; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.PersonDto; |
|
6 |
|
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.List; |
|
9 |
|
|
10 |
public class PersonToDto implements ClassToDto<Person, PersonDto> { |
|
11 |
@Override |
|
12 |
public PersonDto convert(Person source) { |
|
13 |
if (source == null) { |
|
14 |
return null; |
|
15 |
} |
|
16 |
|
|
17 |
IdentityToDto identityToDto = new IdentityToDto(); |
|
18 |
List<IdentityDto> identityDtos = identityToDto.convert(source.getIdentities()); |
|
19 |
|
|
20 |
return PersonDto.builder() |
|
21 |
.id(source.getId()) |
|
22 |
.name(source.getName()) |
|
23 |
.identities(identityDtos) |
|
24 |
.build(); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public List<PersonDto> convert(List<Person> source) { |
|
29 |
List<PersonDto> convertedList = new ArrayList<>(); |
|
30 |
|
|
31 |
if(source == null){ |
|
32 |
return convertedList; |
|
33 |
} |
|
34 |
source.stream().forEach(sourceItem->convertedList.add(this.convert(sourceItem))); |
|
35 |
return convertedList; |
|
36 |
} |
|
37 |
} |
Také k dispozici: Unified diff
https://kivprogrammers.atlassian.net/browse/TSP2-48 Načítání seznamu projektů z api, načítání osob a identit z api, vykreslení