1 |
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.managment;
|
2 |
2 |
|
3 |
3 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.Constants;
|
4 |
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
|
5 |
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Iteration;
|
6 |
7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Phase;
|
|
8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.WorkUnit;
|
|
9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.IterationRepository;
|
|
10 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.PhaseRepository;
|
|
11 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.IterationService;
|
|
12 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.PhaseService;
|
|
13 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.WorkUnitService;
|
7 |
14 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IterationAndPhasesDto;
|
8 |
15 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IterationDto;
|
9 |
16 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.PhaseDto;
|
10 |
17 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.IterationAndPhasesToDto;
|
11 |
18 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.IterationToDto;
|
12 |
19 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.PhaseToDto;
|
|
20 |
import org.springframework.beans.factory.annotation.Autowired;
|
13 |
21 |
import org.springframework.http.HttpStatus;
|
14 |
22 |
import org.springframework.http.ResponseEntity;
|
15 |
23 |
import org.springframework.stereotype.Service;
|
16 |
24 |
|
17 |
|
import java.util.Collections;
|
18 |
|
import java.util.Comparator;
|
19 |
|
import java.util.List;
|
|
25 |
import java.util.*;
|
20 |
26 |
|
21 |
27 |
@Service
|
22 |
28 |
public class IterationsAndPhasesServiceImpl implements IterationsAndPhasesService {
|
23 |
29 |
|
|
30 |
@Autowired
|
|
31 |
private IterationRepository iterationRepository;
|
|
32 |
|
|
33 |
@Autowired
|
|
34 |
private PhaseRepository phaseRepository;
|
|
35 |
|
|
36 |
@Autowired
|
|
37 |
private PhaseService phaseService;
|
|
38 |
|
|
39 |
@Autowired
|
|
40 |
private WorkUnitService workUnitService;
|
|
41 |
|
|
42 |
@Autowired
|
|
43 |
private IterationService iterationService;
|
|
44 |
|
24 |
45 |
@Override
|
25 |
46 |
public ResponseEntity<String> getIterationAndPhases(Project project) {
|
26 |
47 |
ObjectMapper objectMapper = new ObjectMapper();
|
... | ... | |
47 |
68 |
}
|
48 |
69 |
|
49 |
70 |
@Override
|
50 |
|
public ResponseEntity<String> changeToPhase(String[] iterationsIds) {
|
51 |
|
return null;
|
|
71 |
public ResponseEntity<Map<String, Object>> changeToPhase(String[] iterationsIds) {
|
|
72 |
List<Long> iterationIds = new ArrayList<>();
|
|
73 |
for (String id : iterationsIds)
|
|
74 |
iterationIds.add(Long.parseLong(id));
|
|
75 |
List<Iteration> selectedIterations = iterationRepository.fetchIterationsByIds(iterationIds);
|
|
76 |
|
|
77 |
|
|
78 |
StringBuilder message = new StringBuilder();
|
|
79 |
int errors = 0;
|
|
80 |
|
|
81 |
for (Iteration iteration : selectedIterations) {
|
|
82 |
message.append("Iteration: ").append(iteration.getName()).append(System.getProperty("line.separator"));
|
|
83 |
|
|
84 |
if (iteration.getWorkUnits().size() == 0) {
|
|
85 |
errors += 1;
|
|
86 |
message.append(Constants.INDENT)
|
|
87 |
.append("cannot be changed to Phase due to non-existent work unit")
|
|
88 |
.append(System.getProperty("line.separator"))
|
|
89 |
.append(System.getProperty("line.separator"));
|
|
90 |
continue;
|
|
91 |
}
|
|
92 |
|
|
93 |
Phase phase = null;
|
|
94 |
for (WorkUnit workUnit : iteration.getWorkUnits()) { // If exists WorkUnit with empty Phase - create Phase from Iteration
|
|
95 |
if (workUnit.getPhase() == null) {
|
|
96 |
phase = new Phase(iteration.getExternalId(),
|
|
97 |
iteration.getName(),
|
|
98 |
iteration.getDescription(),
|
|
99 |
iteration.getEndDate(),
|
|
100 |
iteration.getStartDate(),
|
|
101 |
iteration.getCreated(),
|
|
102 |
iteration.getSuperProjectId());
|
|
103 |
phaseService.savePhase(phase);
|
|
104 |
break;
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
for (WorkUnit workUnit : iteration.getWorkUnits()) { // For every WorkUnit with empty Phase - assign created Phase
|
|
109 |
Phase workUnitPhrase = workUnit.getPhase();
|
|
110 |
if (workUnitPhrase == null) {
|
|
111 |
workUnit.setPhase(phase);
|
|
112 |
message.append(Constants.INDENT)
|
|
113 |
.append("successfully assigned to WU with id ").append(workUnit.getId())
|
|
114 |
.append(System.getProperty("line.separator"));
|
|
115 |
workUnitService.saveWorkUnit(workUnit);
|
|
116 |
|
|
117 |
} else {
|
|
118 |
errors += 1;
|
|
119 |
message.append(Constants.INDENT)
|
|
120 |
.append("cannot be assigned to WU with id ").append(workUnit.getId())
|
|
121 |
.append(" as it already exists with Phase ").append(workUnit.getPhase().getName())
|
|
122 |
.append(System.getProperty("line.separator"));
|
|
123 |
}
|
|
124 |
if (phase != null) {
|
|
125 |
workUnit.setIteration(null);
|
|
126 |
}
|
|
127 |
if(phase != null || workUnitPhrase == null){
|
|
128 |
workUnitService.saveWorkUnit(workUnit);
|
|
129 |
}
|
|
130 |
}
|
|
131 |
message.append(System.getProperty("line.separator"));
|
|
132 |
if (phase != null) {
|
|
133 |
iteration.setWorkUnits(null);
|
|
134 |
iterationService.deleteIteration(iteration);
|
|
135 |
}
|
|
136 |
}
|
|
137 |
|
|
138 |
Map<String,Object> json = new HashMap<>();
|
|
139 |
json.put("message", message);
|
|
140 |
|
|
141 |
if (errors == 0) {
|
|
142 |
json.put("successMessage", "All selected iterations (" + selectedIterations.size() + ") were transformed to phases");
|
|
143 |
} else {
|
|
144 |
json.put("informMessage", "Some iterations cannot be assign, look at the log for more information");
|
|
145 |
}
|
|
146 |
|
|
147 |
return ResponseEntity.status(HttpStatus.OK).body(json);
|
52 |
148 |
}
|
53 |
149 |
|
54 |
150 |
@Override
|
55 |
|
public ResponseEntity<String> changeToIteration(String[] phasesIds) {
|
56 |
|
return null;
|
|
151 |
public ResponseEntity<Map<String, Object>> changeToIteration(String[] phasesIds) {
|
|
152 |
List<Long> phaseIds = new ArrayList<>();
|
|
153 |
for (String id : phasesIds)
|
|
154 |
phaseIds.add(Long.parseLong(id));
|
|
155 |
List<Phase> selectedPhases = phaseRepository.fetchPhasesByIds(phaseIds);
|
|
156 |
|
|
157 |
StringBuilder message = new StringBuilder();
|
|
158 |
int errors = 0;
|
|
159 |
|
|
160 |
for (Phase phase : selectedPhases) {
|
|
161 |
message.append("Phase: ").append(phase.getName()).append(System.getProperty("line.separator"));
|
|
162 |
|
|
163 |
if (phase.getWorkUnits().size() == 0) {
|
|
164 |
errors += 1;
|
|
165 |
message.append(Constants.INDENT)
|
|
166 |
.append("cannot be changed to Phase due to non-existent work unit")
|
|
167 |
.append(System.getProperty("line.separator"))
|
|
168 |
.append(System.getProperty("line.separator"));
|
|
169 |
continue;
|
|
170 |
}
|
|
171 |
|
|
172 |
Iteration iteration = null;
|
|
173 |
for (WorkUnit workUnit : phase.getWorkUnits()) { // If exists WorkUnit with empty Phase - create Phase from Iteration
|
|
174 |
if (workUnit.getIteration() == null) {
|
|
175 |
iteration = new Iteration(phase.getExternalId(),
|
|
176 |
phase.getName(),
|
|
177 |
phase.getDescription(),
|
|
178 |
phase.getEndDate(),
|
|
179 |
phase.getStartDate(),
|
|
180 |
phase.getCreated(),
|
|
181 |
phase.getSuperProjectId());
|
|
182 |
iterationService.saveIteration(iteration);
|
|
183 |
break;
|
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
for (WorkUnit workUnit : phase.getWorkUnits()) { // For every WorkUnit with empty Phase - assign created Phase
|
|
188 |
if (workUnit.getIteration() == null) {
|
|
189 |
workUnit.setIteration(iteration);
|
|
190 |
workUnitService.saveWorkUnit(workUnit);
|
|
191 |
message.append(Constants.INDENT)
|
|
192 |
.append("successfully assigned to WU with id ").append(workUnit.getId())
|
|
193 |
.append(System.getProperty("line.separator"));
|
|
194 |
} else {
|
|
195 |
errors += 1;
|
|
196 |
message.append(Constants.INDENT)
|
|
197 |
.append("cannot be assigned to WU with id ").append(workUnit.getId())
|
|
198 |
.append(" as it already exists with Iteration ").append(workUnit.getIteration().getName())
|
|
199 |
.append(System.getProperty("line.separator"));
|
|
200 |
}
|
|
201 |
if (iteration != null) {
|
|
202 |
workUnit.setPhase(null);
|
|
203 |
}
|
|
204 |
workUnitService.saveWorkUnit(workUnit);
|
|
205 |
}
|
|
206 |
message.append(System.getProperty("line.separator"));
|
|
207 |
if (iteration != null) {
|
|
208 |
phase.setWorkUnits(null);
|
|
209 |
phaseService.deletePhase(phase);
|
|
210 |
}
|
|
211 |
}
|
|
212 |
|
|
213 |
Map<String,Object> json = new HashMap<>();
|
|
214 |
json.put("message", message);
|
|
215 |
|
|
216 |
if (errors == 0) {
|
|
217 |
json.put("successMessage", "All selected iterations (" + selectedPhases.size() + ") were transformed to phases");
|
|
218 |
} else {
|
|
219 |
json.put("informMessage", "Some iterations cannot be assign, look at the log for more information");
|
|
220 |
}
|
|
221 |
|
|
222 |
return ResponseEntity.status(HttpStatus.OK).body(json);
|
57 |
223 |
}
|
58 |
224 |
|
59 |
225 |
}
|
https://kivprogrammers.atlassian.net/browse/TSP2-50 zpracování dat z frontendu, posílání odpovědí