Revize 627559bc
Přidáno uživatelem stepanekp před více než 1 rok
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/Project.java | ||
---|---|---|
15 | 15 |
public class Project { |
16 | 16 |
|
17 | 17 |
@Id |
18 |
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
18 |
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
19 | 19 |
@Column(name = "id", nullable = false) |
20 | 20 |
private Long id; |
21 | 21 |
|
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/CommittedConfiguration.java | ||
---|---|---|
9 | 9 |
* Model class for configurations. This is Entity class that is loaded from db. |
10 | 10 |
*/ |
11 | 11 |
@Entity |
12 |
@Table(name = "committed_configuration") |
|
12 | 13 |
public class CommittedConfiguration { |
13 | 14 |
|
14 | 15 |
@OneToOne |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/ProjectInstance.java | ||
---|---|---|
14 | 14 |
* Model class for project instances. This is Entity class that is loaded from db. |
15 | 15 |
*/ |
16 | 16 |
@Entity |
17 |
@Table(name = "project_instance") |
|
17 | 18 |
public class ProjectInstance { |
18 | 19 |
|
19 | 20 |
@Id |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/WorkItem.java | ||
---|---|---|
9 | 9 |
* Model class for workitems. This is Entity class that is loaded from db. |
10 | 10 |
*/ |
11 | 11 |
@Entity |
12 |
@Table(name = "work_item") |
|
12 | 13 |
public class WorkItem { |
13 | 14 |
|
14 | 15 |
@Id |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/WorkUnit.java | ||
---|---|---|
13 | 13 |
* Model class for work units. This is Entity class that is loaded from db. |
14 | 14 |
*/ |
15 | 15 |
@Entity |
16 |
@Table(name = "work_unit") |
|
16 | 17 |
public class WorkUnit { |
17 | 18 |
|
18 | 19 |
@Id |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/enums/WuType.java | ||
---|---|---|
10 | 10 |
* Model class for work unit types. This is Entity class that is loaded from db. |
11 | 11 |
*/ |
12 | 12 |
@Entity |
13 |
@Table(name = "wu_type") |
|
13 | 14 |
public class WuType implements EnumType { |
14 | 15 |
|
15 | 16 |
@Id |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/enums/WuTypeClassification.java | ||
---|---|---|
10 | 10 |
* Model class for work unit types classes. This is Entity class that is loaded from db. |
11 | 11 |
*/ |
12 | 12 |
@Entity |
13 |
@Table(name = "wu_type_classification") |
|
13 | 14 |
public class WuTypeClassification implements Classification { |
14 | 15 |
|
15 | 16 |
@Id |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/ProjectService.java | ||
---|---|---|
56 | 56 |
* @return List of project's children with their hierarchy |
57 | 57 |
*/ |
58 | 58 |
ArrayList<Node> calculate(ProjectDto p); |
59 |
|
|
60 |
/** |
|
61 |
* Method saving new structure of the projects and superprojects |
|
62 |
* @param nodes List of the nodes with projects to save |
|
63 |
* @param superProject Parent of the projects in the list |
|
64 |
* @return true if successful |
|
65 |
*/ |
|
66 |
boolean saveProjectsStructure(List<Node> nodes, Project superProject); |
|
59 | 67 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/ProjectServiceImpl.java | ||
---|---|---|
75 | 75 |
} |
76 | 76 |
return nodes; |
77 | 77 |
} |
78 |
|
|
79 |
@Override |
|
80 |
public boolean saveProjectsStructure(List<Node> nodes, Project superProject) { |
|
81 |
if (nodes != null && !nodes.isEmpty()) { |
|
82 |
for (Node node : nodes) { |
|
83 |
ProjectDto projectDto = node.project; |
|
84 |
Project project = new Project(); |
|
85 |
|
|
86 |
if(projectDto.getId() > 0) { |
|
87 |
project.setId(projectDto.getId()); |
|
88 |
} |
|
89 |
|
|
90 |
project.setName(projectDto.getName()); |
|
91 |
project.setDescription(projectDto.getDescription()); |
|
92 |
|
|
93 |
if(superProject != null) { |
|
94 |
project.setSuperProject(superProject); |
|
95 |
} |
|
96 |
|
|
97 |
project = projectRepository.save(project); // This may update an existing project or insert a new one |
|
98 |
|
|
99 |
if (node.children != null && !node.children.isEmpty()) { |
|
100 |
List<Node> children = node.children; |
|
101 |
saveProjectsStructure(children, project); |
|
102 |
} |
|
103 |
} |
|
104 |
return true; // Success |
|
105 |
} |
|
106 |
return false; // No data to save |
|
107 |
} |
|
78 | 108 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/ProjectController.java | ||
---|---|---|
1 | 1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller.management; |
2 | 2 |
|
3 |
import com.fasterxml.jackson.core.JsonProcessingException; |
|
3 | 4 |
import com.google.gson.Gson; |
4 | 5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.types.Node; |
5 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService; |
6 | 7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.ProjectDto; |
8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.JSONBuilder; |
|
7 | 9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.ProjectToDto; |
8 | 10 |
import org.springframework.beans.factory.annotation.Autowired; |
9 | 11 |
import org.springframework.http.HttpStatus; |
10 | 12 |
import org.springframework.http.ResponseEntity; |
11 | 13 |
import org.springframework.stereotype.Controller; |
12 | 14 |
import org.springframework.web.bind.annotation.GetMapping; |
15 |
import org.springframework.web.bind.annotation.PostMapping; |
|
16 |
import org.springframework.web.bind.annotation.RequestBody; |
|
13 | 17 |
import org.springframework.web.bind.annotation.RequestMapping; |
18 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
14 | 19 |
|
15 |
import java.util.ArrayList; |
|
16 |
import java.util.List; |
|
20 |
import java.util.*; |
|
17 | 21 |
|
18 | 22 |
|
19 | 23 |
/** |
... | ... | |
45 | 49 |
return ResponseEntity.status(parents.size() > 0 ? HttpStatus.OK : HttpStatus.NO_CONTENT).body(new Gson().toJson(parents)); |
46 | 50 |
} |
47 | 51 |
|
52 |
@PostMapping("/saveProjects") |
|
53 |
public ResponseEntity<String> saveProjects(@RequestBody Map<String, Object> requestData) throws JsonProcessingException { |
|
54 |
ObjectMapper objectMapper = new ObjectMapper(); |
|
55 |
|
|
56 |
String nodesString = objectMapper.writeValueAsString(requestData.get("projects")); |
|
57 |
Node[] nodes = objectMapper.readValue(nodesString, Node[].class); |
|
58 |
|
|
59 |
Map<String, Object> json = new HashMap<>(); |
|
60 |
|
|
61 |
if(projectService.saveProjectsStructure(Arrays.asList(nodes), null)) { |
|
62 |
json.put("message", "Project data saved successfully."); |
|
63 |
return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.OK); |
|
64 |
} |
|
65 |
else { |
|
66 |
json.put("message", "Project data save failed."); |
|
67 |
return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.INTERNAL_SERVER_ERROR); |
|
68 |
|
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
|
|
48 | 73 |
} |
49 | 74 |
|
Také k dispozici: Unified diff
https://kivprogrammers.atlassian.net/browse/TSP2-37 načítání projektů a ukládání na SPADe