Revision 57964
Added by Konstantina Galouni over 4 years ago
IndicatorController.java | ||
---|---|---|
10 | 10 |
import org.springframework.web.bind.annotation.*; |
11 | 11 |
|
12 | 12 |
import java.util.ArrayList; |
13 |
import java.util.Iterator; |
|
14 | 13 |
import java.util.List; |
15 | 14 |
import java.util.Map; |
16 | 15 |
|
... | ... | |
32 | 31 |
private SubCategoryDAO subCategoryDAO; |
33 | 32 |
|
34 | 33 |
@Autowired |
34 |
private SectionDAO sectionDAO; |
|
35 |
|
|
36 |
@Autowired |
|
35 | 37 |
private IndicatorDAO indicatorDAO; |
36 | 38 |
|
37 | 39 |
|
38 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save", method = RequestMethod.POST) |
|
40 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/save", method = RequestMethod.POST)
|
|
39 | 41 |
public Indicator saveIndicator(@PathVariable("stakeholderId") String stakeholderId, |
40 | 42 |
@PathVariable("topicId") String topicId, |
41 | 43 |
@PathVariable("categoryId") String categoryId, |
42 | 44 |
@PathVariable("subcategoryId") String subcategoryId, |
45 |
@PathVariable("sectionId") String sectionId, |
|
43 | 46 |
@RequestBody Indicator indicator) { |
44 | 47 |
log.debug("save indicator"); |
45 |
log.debug("Name: "+indicator.getName() + " - Id: "+indicator.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
48 |
log.debug("Name: "+indicator.getName() + " - Id: "+indicator.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
|
|
46 | 49 |
|
47 |
// if(stakeholderId == null) { |
|
48 |
// // EXCEPTION - Parameter for Stakeholder is not accepted |
|
49 |
// } |
|
50 |
// if(topicId == null) { |
|
51 |
// // EXCEPTION - Parameter for Topic is not accepted |
|
52 |
// } |
|
53 |
// if(categoryId == null) { |
|
54 |
// // EXCEPTION - Parameter for Category is not accepted |
|
55 |
// } |
|
56 |
// if(subcategoryId == null) { |
|
57 |
// // EXCEPTION - Parameter for SubCategory is not accepted |
|
58 |
// } |
|
59 |
// if(indicator == null) { |
|
60 |
// // EXCEPTION - Parameter for Indicator is not accepted |
|
61 |
// } |
|
50 |
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType()); |
|
62 | 51 |
|
52 |
String indicatorId = indicator.getId(); |
|
53 |
indicatorDAO.save(indicator); |
|
54 |
|
|
63 | 55 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
56 |
// this indicator belongs in default profile and it is new or it is updated |
|
57 |
if(stakeholder.getDefaultId() == null) { |
|
58 |
if(indicatorId == null) { |
|
59 |
onSaveDefaultIndicator(indicator, sectionId); |
|
60 |
} |
|
61 |
else { |
|
62 |
onUpdateDefaultIndicator(indicator, stakeholder); |
|
63 |
} |
|
64 |
} |
|
64 | 65 |
|
65 |
if(stakeholder != null) {
|
|
66 |
List<String> indicators = section.getIndicators();
|
|
66 | 67 |
|
67 |
Topic<String> topic = topicDAO.findById(topicId); |
|
68 |
if(topic != null) { |
|
69 |
if(stakeholder.getTopics().contains(topicId)) { |
|
68 |
int index = indicators.indexOf(indicator.getId()); |
|
69 |
if (index == -1) { |
|
70 |
indicators.add(indicator.getId()); |
|
71 |
sectionDAO.save(section); |
|
72 |
log.debug("Indicator saved!"); |
|
73 |
} |
|
70 | 74 |
|
71 |
Category<String> category = categoryDAO.findById(categoryId); |
|
72 |
if(category != null) { |
|
73 |
if(topic.getCategories().contains(categoryId)) { |
|
74 |
|
|
75 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
76 |
if(subcategory != null) { |
|
77 |
if (category.getSubCategories().contains(subcategoryId)) { |
|
78 |
String indicatorId = indicator.getId(); |
|
79 |
indicatorDAO.save(indicator); |
|
80 |
|
|
81 |
// this indicator belongs in default profile and it is new or it is updated |
|
82 |
if(stakeholder.getDefaultId() == null) { |
|
83 |
if(indicatorId == null) { |
|
84 |
onSaveDefaultIndicator(indicator, topicId, categoryId, subcategoryId, stakeholder); |
|
85 |
} |
|
86 |
else { |
|
87 |
onUpdateDefaultIndicator(indicator, stakeholder); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
List<String> indicators = null; |
|
92 |
//if(indicator.hasType("chart")) { |
|
93 |
if(indicator.getType().equals("chart")) { |
|
94 |
indicators = subcategory.getCharts(); |
|
95 |
//} else if(indicator.hasType("number")) { |
|
96 |
} else if(indicator.getType().equals("number")) { |
|
97 |
indicators = subcategory.getNumbers(); |
|
98 |
} |
|
99 |
|
|
100 |
int index = indicators.indexOf(indicator.getId()); |
|
101 |
if (index == -1) { |
|
102 |
indicators.add(indicator.getId()); |
|
103 |
subCategoryDAO.save(subcategory); |
|
104 |
log.debug("Indicator saved!"); |
|
105 |
|
|
106 |
indicator.setId(indicator.getId()); |
|
107 |
} |
|
108 |
} else { |
|
109 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
110 |
throw new PathNotValidException("Save indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
111 |
} |
|
112 |
} else { |
|
113 |
// EXCEPTION - SubCategory not found |
|
114 |
throw new EntityNotFoundException("Save indicator: SubCategory with id: "+subcategoryId+" not found"); |
|
115 |
} |
|
116 |
} else { |
|
117 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
118 |
throw new PathNotValidException("Save indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
119 |
} |
|
120 |
} else { |
|
121 |
// EXCEPTION - Category not found |
|
122 |
throw new EntityNotFoundException("Save indicator: Category with id: "+categoryId+" not found"); |
|
123 |
} |
|
124 |
} else { |
|
125 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
126 |
throw new PathNotValidException("Save indicator: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
127 |
} |
|
128 |
} else { |
|
129 |
// EXCEPTION - Topic not found |
|
130 |
throw new EntityNotFoundException("Save indicator: Topic with id: "+topicId+" not found"); |
|
131 |
} |
|
132 |
} else { |
|
133 |
// EXCEPTION - Stakeholder not found |
|
134 |
throw new EntityNotFoundException("Save indicator: Stakeholder with id: "+stakeholderId+" not found"); |
|
135 |
} |
|
136 | 75 |
return indicator; |
137 | 76 |
} |
138 | 77 |
|
139 |
public void onSaveDefaultIndicator(Indicator indicator, |
|
140 |
String defaultTopicId, String defaultCategoryId, |
|
141 |
String defaultSubcategoryId, Stakeholder defaultStakeholder) { |
|
78 |
public void onSaveDefaultIndicator(Indicator indicator, String defaultSectionId) { |
|
142 | 79 |
log.debug("On save default indicator"); |
143 | 80 |
|
144 |
// List<Stakeholder> stakeholders = stakeholderDAO.findByDefaultId(defaultStakeholder.getId()); |
|
145 |
// for(Stakeholder stakeholder : stakeholders) { |
|
146 |
// List<String> topicIds = stakeholder.getTopics(); |
|
147 |
// Topic topic = null; |
|
148 |
// for(String topicId : topicIds) { |
|
149 |
// topic = topicDAO.findById(topicId); |
|
150 |
// if(topic.getDefaultId().equals(defaultTopicId)) { |
|
151 |
// break; |
|
152 |
// } |
|
153 |
// } |
|
154 |
// |
|
155 |
// List<String> categoryIds = topic.getCategories(); |
|
156 |
// Category category = null; |
|
157 |
// for(String categoryId : categoryIds) { |
|
158 |
// category = categoryDAO.findById(categoryId); |
|
159 |
// if(category.getDefaultId().equals(defaultCategoryId)) { |
|
160 |
// break; |
|
161 |
// } |
|
162 |
// } |
|
163 |
// |
|
164 |
// List<String> subCategoryIds = category.getSubCategories(); |
|
165 |
// SubCategory subCategory = null; |
|
166 |
// for(String subCategoryId : subCategoryIds) { |
|
167 |
// subCategory = subCategoryDAO.findById(subCategoryId); |
|
168 |
// if(subCategory.getDefaultId().equals(defaultSubcategoryId)) { |
|
169 |
// break; |
|
170 |
// } |
|
171 |
// } |
|
172 |
// |
|
173 |
// Indicator indicatorNew = new Indicator(indicator); |
|
174 |
// //indicatorNew.setStakeholderId(defaultStakeholder.getId()); |
|
175 |
// for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) { |
|
176 |
// parameterMapping(indicatorPath, stakeholder); |
|
177 |
// } |
|
178 |
// |
|
179 |
// indicatorDAO.save(indicatorNew); |
|
180 |
// |
|
181 |
// List<String> indicators = null; |
|
182 |
// if (indicator.getType().equals("chart")) { |
|
183 |
// indicators = subCategory.getCharts(); |
|
184 |
// } else if (indicator.getType().equals("number")) { |
|
185 |
// indicators = subCategory.getNumbers(); |
|
186 |
// } |
|
187 |
// indicators.add(indicatorNew.getId()); |
|
188 |
// |
|
189 |
// subCategoryDAO.save(subCategory); |
|
190 |
// } |
|
191 |
|
|
192 |
|
|
193 | 81 |
// new indicator in default profile - add it on profiles of the same type |
194 |
List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubcategoryId);
|
|
82 |
List<Section> sections = sectionDAO.findByDefaultId(defaultSectionId);
|
|
195 | 83 |
|
196 |
for (SubCategory subCategory : subCategories) {
|
|
84 |
for (Section section : sections) {
|
|
197 | 85 |
Indicator indicatorNew = new Indicator(); |
198 | 86 |
indicatorNew.copyFromDefault(indicator); |
199 | 87 |
for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) { |
200 |
Stakeholder stakeholder = stakeholderDAO.findById(subCategory.getStakeholderId());
|
|
88 |
Stakeholder stakeholder = stakeholderDAO.findByAlias(section.getStakeholderAlias());
|
|
201 | 89 |
parameterMapping(indicatorPath, stakeholder); |
202 | 90 |
} |
203 | 91 |
|
204 | 92 |
indicatorDAO.save(indicatorNew); |
205 | 93 |
|
206 |
List<String> indicators = null; |
|
207 |
if (indicator.getType().equals("chart")) { |
|
208 |
indicators = subCategory.getCharts(); |
|
209 |
} else if (indicator.getType().equals("number")) { |
|
210 |
indicators = subCategory.getNumbers(); |
|
211 |
} |
|
94 |
List<String> indicators = section.getIndicators(); |
|
212 | 95 |
indicators.add(indicatorNew.getId()); |
213 | 96 |
|
214 |
subCategoryDAO.save(subCategory);
|
|
97 |
sectionDAO.save(section);
|
|
215 | 98 |
} |
216 | 99 |
} |
217 | 100 |
|
... | ... | |
292 | 175 |
} |
293 | 176 |
} |
294 | 177 |
|
295 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/delete", method = RequestMethod.DELETE) |
|
178 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/delete", method = RequestMethod.DELETE)
|
|
296 | 179 |
public boolean deleteIndicator(@PathVariable("stakeholderId") String stakeholderId, |
297 | 180 |
@PathVariable("topicId") String topicId, |
298 | 181 |
@PathVariable("categoryId") String categoryId, |
299 | 182 |
@PathVariable("subcategoryId") String subcategoryId, |
183 |
@PathVariable("sectionId") String sectionId, |
|
300 | 184 |
@PathVariable("indicatorId") String indicatorId) { |
301 | 185 |
log.debug("delete indicator"); |
302 |
log.debug("Id: "+indicatorId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
186 |
log.debug("Id: "+indicatorId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
|
|
303 | 187 |
|
304 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
|
188 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
|
189 |
if(indicator != null) { |
|
190 |
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType()); |
|
305 | 191 |
|
306 |
if(stakeholder != null) {
|
|
192 |
List<String> indicators = section.getIndicators();
|
|
307 | 193 |
|
308 |
Topic<String> topic = topicDAO.findById(topicId); |
|
309 |
if(topic != null) { |
|
310 |
if(stakeholder.getTopics().contains(topicId)) { |
|
194 |
int index = indicators.indexOf(indicatorId); |
|
195 |
if (index != -1) { |
|
196 |
indicators.remove(index); |
|
197 |
sectionDAO.save(section); |
|
311 | 198 |
|
312 |
Category<String> category = categoryDAO.findById(categoryId); |
|
313 |
if(category != null) { |
|
314 |
if(topic.getCategories().contains(categoryId)) { |
|
315 |
|
|
316 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
317 |
if(subcategory != null) { |
|
318 |
if(category.getSubCategories().contains(subcategoryId)) { |
|
319 |
|
|
320 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
|
321 |
if(indicator != null) { |
|
322 |
List<String> indicators = null; |
|
323 |
if (indicator.getType().equals("chart")) { |
|
324 |
indicators = subcategory.getCharts(); |
|
325 |
} else if (indicator.getType().equals("number")) { |
|
326 |
indicators = subcategory.getNumbers(); |
|
327 |
} |
|
328 |
|
|
329 |
int index = indicators.indexOf(indicatorId); |
|
330 |
if (index != -1) { |
|
331 |
indicators.remove(index); |
|
332 |
subCategoryDAO.save(subcategory); |
|
333 |
|
|
334 |
indicatorDAO.delete(indicatorId); |
|
335 |
log.debug("Indicator deleted!"); |
|
336 |
} else { |
|
337 |
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); |
|
338 |
throw new PathNotValidException("Delete indicator: Indicator with id: "+indicatorId+" not found in SubCategory: "+subcategoryId); |
|
339 |
} |
|
340 |
} else { |
|
341 |
// EXCEPTION - Indicator not found |
|
342 |
throw new EntityNotFoundException("Delete indicator: Indicator with id: "+indicatorId+" not found"); |
|
343 |
} |
|
344 |
} else { |
|
345 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
346 |
throw new PathNotValidException("Delete indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
347 |
} |
|
348 |
} else { |
|
349 |
// EXCEPTION - SubCategory not found |
|
350 |
throw new EntityNotFoundException("Delete indicator: SubCategory with id: "+subcategoryId+" not found"); |
|
351 |
} |
|
352 |
} else { |
|
353 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
354 |
throw new PathNotValidException("Delete indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
355 |
} |
|
356 |
} else { |
|
357 |
// EXCEPTION - Category not found |
|
358 |
throw new EntityNotFoundException("Delete indicator: Category with id: "+categoryId+" not found"); |
|
359 |
} |
|
360 |
} else { |
|
361 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
362 |
throw new PathNotValidException("Delete indicator: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
363 |
} |
|
199 |
indicatorDAO.delete(indicatorId); |
|
200 |
log.debug("Indicator deleted!"); |
|
364 | 201 |
} else { |
365 |
// EXCEPTION - Topic not found
|
|
366 |
throw new EntityNotFoundException("Delete indicator: Topic with id: "+topicId+" not found");
|
|
202 |
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); -> Section: section.getTitle();
|
|
203 |
throw new PathNotValidException("Delete indicator: Indicator with id: "+indicatorId+" not found in Sectiom: "+sectionId);
|
|
367 | 204 |
} |
368 | 205 |
} else { |
369 |
// EXCEPTION - Stakeholder not found
|
|
370 |
throw new EntityNotFoundException("Delete indicator: Stakeholder with id: "+stakeholderId+" not found");
|
|
206 |
// EXCEPTION - Indicator not found
|
|
207 |
throw new EntityNotFoundException("Delete indicator: Indicator with id: "+indicatorId+" not found");
|
|
371 | 208 |
} |
372 | 209 |
return true; |
373 | 210 |
} |
374 | 211 |
|
375 |
@RequestMapping(value = "/{stakeholderId}/charts/delete", method = RequestMethod.DELETE) |
|
376 |
public boolean deleteAllChartIndicators(@PathVariable("stakeholderId") String stakeholderId) { |
|
377 |
log.debug("delete all chart indicators of stakeholder"); |
|
378 |
log.debug("Stakeholder: "+stakeholderId); |
|
212 |
// @RequestMapping(value = "/{stakeholderId}/charts/delete", method = RequestMethod.DELETE) |
|
213 |
// public boolean deleteAllChartIndicators(@PathVariable("stakeholderId") String stakeholderId) { |
|
214 |
// log.debug("delete all chart indicators of stakeholder"); |
|
215 |
// log.debug("Stakeholder: "+stakeholderId); |
|
216 |
// |
|
217 |
// Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
|
218 |
// if(stakeholder != null) { |
|
219 |
// |
|
220 |
// for(String topicId : stakeholder.getTopics()) { |
|
221 |
// Topic<String> topic = topicDAO.findById(topicId); |
|
222 |
// if(topic != null) { |
|
223 |
// for(String categoryId : topic.getCategories()) { |
|
224 |
// Category<String> category = categoryDAO.findById(categoryId); |
|
225 |
// if(category != null) { |
|
226 |
// for(String subcategoryId : category.getSubCategories()) { |
|
227 |
// SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
228 |
// if(subcategory != null) { |
|
229 |
// |
|
230 |
// for(String sectionId : subcategory.getCharts()) { |
|
231 |
// Section<String> section = sectionDAO.findById(sectionId); |
|
232 |
// if (section != null) { |
|
233 |
// |
|
234 |
// List<String> indicators = section.getIndicators(); |
|
235 |
// Iterator<String> indicatorsIterator = section.getIndicators().iterator(); |
|
236 |
// |
|
237 |
// while (indicatorsIterator.hasNext()) { |
|
238 |
// String indicatorId = indicatorsIterator.next(); |
|
239 |
// Indicator indicator = indicatorDAO.findById(indicatorId); |
|
240 |
// if (indicator != null) { |
|
241 |
// int index = indicators.indexOf(indicatorId); |
|
242 |
// if (index != -1) { |
|
243 |
// indicatorsIterator.remove(); |
|
244 |
// //indicators.remove(index); |
|
245 |
// |
|
246 |
// indicatorDAO.delete(indicatorId); |
|
247 |
// log.debug("Indicator deleted!"); |
|
248 |
// } else { |
|
249 |
// // EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); -> Section: section.getTitle(); |
|
250 |
// throw new PathNotValidException("Delete indicator: Indicator with id: " + indicatorId + " not found in Section: " + sectionId); |
|
251 |
// } |
|
252 |
// } else { |
|
253 |
// // EXCEPTION - Indicator not found |
|
254 |
// throw new EntityNotFoundException("Delete indicator: Indicator with id: " + indicatorId + " not found"); |
|
255 |
// } |
|
256 |
// } |
|
257 |
// sectionDAO.save(section); |
|
258 |
// } else { |
|
259 |
// // EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); |
|
260 |
// throw new PathNotValidException("Delete indicator: Section with id: " + sectionId + " not found in SubCategory: " + subcategoryId); |
|
261 |
// } |
|
262 |
// } |
|
263 |
// } else { |
|
264 |
// // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
265 |
// throw new PathNotValidException("Delete indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
266 |
// } |
|
267 |
// } |
|
268 |
// } else { |
|
269 |
// // EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
270 |
// throw new PathNotValidException("Delete indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
271 |
// } |
|
272 |
// } |
|
273 |
// } else { |
|
274 |
// // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
275 |
// throw new PathNotValidException("Delete indicator: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
276 |
// } |
|
277 |
// } |
|
278 |
// } else { |
|
279 |
// // EXCEPTION - Stakeholder not found |
|
280 |
// throw new EntityNotFoundException("Delete indicator: Stakeholder with id: "+stakeholderId+" not found"); |
|
281 |
// } |
|
282 |
// return true; |
|
283 |
// } |
|
379 | 284 |
|
380 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
|
381 |
if(stakeholder != null) { |
|
382 |
|
|
383 |
for(String topicId : stakeholder.getTopics()) { |
|
384 |
Topic<String> topic = topicDAO.findById(topicId); |
|
385 |
if(topic != null) { |
|
386 |
for(String categoryId : topic.getCategories()) { |
|
387 |
Category<String> category = categoryDAO.findById(categoryId); |
|
388 |
if(category != null) { |
|
389 |
for(String subcategoryId : category.getSubCategories()) { |
|
390 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
391 |
if(subcategory != null) { |
|
392 |
|
|
393 |
List<String> indicators = subcategory.getCharts(); |
|
394 |
Iterator<String> indicatorsIterator = subcategory.getCharts().iterator(); |
|
395 |
|
|
396 |
while (indicatorsIterator.hasNext()) { |
|
397 |
String indicatorId = indicatorsIterator.next(); |
|
398 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
|
399 |
if (indicator != null) { |
|
400 |
int index = indicators.indexOf(indicatorId); |
|
401 |
if (index != -1) { |
|
402 |
indicatorsIterator.remove(); |
|
403 |
//indicators.remove(index); |
|
404 |
|
|
405 |
indicatorDAO.delete(indicatorId); |
|
406 |
log.debug("Indicator deleted!"); |
|
407 |
} else { |
|
408 |
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); |
|
409 |
throw new PathNotValidException("Delete indicator: Indicator with id: " + indicatorId + " not found in SubCategory: " + subcategoryId); |
|
410 |
} |
|
411 |
} else { |
|
412 |
// EXCEPTION - Indicator not found |
|
413 |
throw new EntityNotFoundException("Delete indicator: Indicator with id: " + indicatorId + " not found"); |
|
414 |
} |
|
415 |
} |
|
416 |
subCategoryDAO.save(subcategory); |
|
417 |
} else { |
|
418 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
419 |
throw new PathNotValidException("Delete indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
420 |
} |
|
421 |
} |
|
422 |
} else { |
|
423 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
424 |
throw new PathNotValidException("Delete indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
425 |
} |
|
426 |
} |
|
427 |
} else { |
|
428 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
429 |
throw new PathNotValidException("Delete indicator: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
430 |
} |
|
431 |
} |
|
432 |
} else { |
|
433 |
// EXCEPTION - Stakeholder not found |
|
434 |
throw new EntityNotFoundException("Delete indicator: Stakeholder with id: "+stakeholderId+" not found"); |
|
435 |
} |
|
436 |
return true; |
|
437 |
} |
|
438 |
|
|
439 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder", method = RequestMethod.POST) |
|
285 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{type}/reorder", method = RequestMethod.POST) |
|
440 | 286 |
public List<Indicator> reorderIndicators(@PathVariable("stakeholderId") String stakeholderId, |
441 |
@PathVariable("topicId") String topicId, |
|
442 |
@PathVariable("categoryId") String categoryId, |
|
443 |
@PathVariable("subcategoryId") String subcategoryId, |
|
444 |
@PathVariable("type") String type, |
|
445 |
@RequestBody List<String> indicators) { |
|
287 |
@PathVariable("topicId") String topicId, |
|
288 |
@PathVariable("categoryId") String categoryId, |
|
289 |
@PathVariable("subcategoryId") String subcategoryId, |
|
290 |
@PathVariable("sectionId") String sectionId, |
|
291 |
@PathVariable("type") String type, |
|
292 |
@RequestBody List<String> indicators) { |
|
446 | 293 |
log.debug("reorder indicators of type: "+type); |
447 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
294 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
|
|
448 | 295 |
|
449 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
|
|
296 |
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, type);
|
|
450 | 297 |
|
451 |
if (stakeholder != null) {
|
|
298 |
section.setIndicators(indicators);
|
|
452 | 299 |
|
453 |
Topic<String> topic = topicDAO.findById(topicId); |
|
454 |
if (topic != null) { |
|
455 |
if (stakeholder.getTopics().contains(topicId)) { |
|
300 |
sectionDAO.save(section); |
|
301 |
log.debug("Indicators reordered!"); |
|
456 | 302 |
|
457 |
Category<String> category = categoryDAO.findById(categoryId); |
|
458 |
if (category != null) { |
|
459 |
if (topic.getCategories().contains(categoryId)) { |
|
460 |
|
|
461 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
462 |
if (subcategory != null) { |
|
463 |
if (category.getSubCategories().contains(subcategoryId)) { |
|
464 |
if(type.equals("chart")) { |
|
465 |
subcategory.setCharts(indicators); |
|
466 |
} else if(type.equals("number")) { |
|
467 |
subcategory.setNumbers(indicators); |
|
468 |
} |
|
469 |
|
|
470 |
subCategoryDAO.save(subcategory); |
|
471 |
log.debug("Indicators reordered!"); |
|
472 |
} else { |
|
473 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
474 |
throw new PathNotValidException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
475 |
} |
|
476 |
} else { |
|
477 |
// EXCEPTION - SubCategory not found |
|
478 |
throw new EntityNotFoundException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found"); |
|
479 |
} |
|
480 |
} else { |
|
481 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
482 |
throw new PathNotValidException("Reorder indicators: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
483 |
} |
|
484 |
} else { |
|
485 |
// EXCEPTION - Category not found |
|
486 |
throw new EntityNotFoundException("Reorder indicators: Category with id: "+categoryId+" not found"); |
|
487 |
} |
|
488 |
} else { |
|
489 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
490 |
throw new PathNotValidException("Reorder indicators: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
491 |
} |
|
492 |
} else { |
|
493 |
// EXCEPTION - Topic not found |
|
494 |
throw new EntityNotFoundException("Reorder indicators: Topic with id: "+topicId+" not found"); |
|
495 |
} |
|
496 |
} else { |
|
497 |
// EXCEPTION - Stakeholder not found |
|
498 |
throw new EntityNotFoundException("Reorder indicators: Stakeholder with id: "+stakeholderId+" not found"); |
|
499 |
} |
|
500 |
|
|
501 | 303 |
List<Indicator> indicatorsFull = new ArrayList<>(); |
502 | 304 |
for(String indicatorId : indicators) { |
503 | 305 |
indicatorsFull.add(indicatorDAO.findById(indicatorId)); |
... | ... | |
505 | 307 |
return indicatorsFull; |
506 | 308 |
} |
507 | 309 |
|
508 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/toggle-status", method = RequestMethod.POST) |
|
310 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/toggle-status", method = RequestMethod.POST)
|
|
509 | 311 |
public Boolean toggleIndicatorStatus(@PathVariable("stakeholderId") String stakeholderId, |
510 | 312 |
@PathVariable("topicId") String topicId, |
511 | 313 |
@PathVariable("categoryId") String categoryId, |
512 | 314 |
@PathVariable("subcategoryId") String subcategoryId, |
315 |
@PathVariable("sectionId") String sectionId, |
|
513 | 316 |
@PathVariable("indicatorId") String indicatorId) { |
514 | 317 |
log.debug("toggle indicator status (isActive)"); |
515 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Indicator: "+indicatorId); |
|
318 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId+ " - Indicator: "+indicatorId);
|
|
516 | 319 |
|
517 | 320 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
518 | 321 |
if (indicator == null) { |
... | ... | |
521 | 324 |
} |
522 | 325 |
indicator.setIsActive(!indicator.getIsActive()); |
523 | 326 |
|
524 |
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, indicator); |
|
327 |
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator);
|
|
525 | 328 |
|
526 | 329 |
return indicator.getIsActive(); |
527 | 330 |
} |
528 | 331 |
|
529 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/toggle-access", method = RequestMethod.POST) |
|
332 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/toggle-access", method = RequestMethod.POST)
|
|
530 | 333 |
public Boolean toggleIndicatorAccess(@PathVariable("stakeholderId") String stakeholderId, |
531 | 334 |
@PathVariable("topicId") String topicId, |
532 | 335 |
@PathVariable("categoryId") String categoryId, |
533 | 336 |
@PathVariable("subcategoryId") String subcategoryId, |
337 |
@PathVariable("sectionId") String sectionId, |
|
534 | 338 |
@PathVariable("indicatorId") String indicatorId) { |
535 | 339 |
log.debug("toggle indicator access (isPublic)"); |
536 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Indicator: "+indicatorId); |
|
340 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId+ " - Indicator: "+indicatorId);
|
|
537 | 341 |
|
538 | 342 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
539 | 343 |
if (indicator == null) { |
... | ... | |
542 | 346 |
} |
543 | 347 |
indicator.setIsPublic(!indicator.getIsPublic()); |
544 | 348 |
|
545 |
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, indicator); |
|
349 |
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator);
|
|
546 | 350 |
|
547 | 351 |
return indicator.getIsPublic(); |
548 | 352 |
} |
549 | 353 |
|
550 |
public void toggleIndicator(String stakeholderId, String topicId, String categoryId, String subcategoryId, Indicator indicator) { |
|
354 |
public void toggleIndicator(String stakeholderId, String topicId, String categoryId, String subcategoryId, String sectionId, Indicator indicator) { |
|
355 |
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType()); |
|
356 |
List<String> indicators = section.getIndicators(); |
|
357 |
|
|
358 |
if(indicators.contains(indicator.getId())) { |
|
359 |
indicatorDAO.save(indicator); |
|
360 |
log.debug("Indicator toggled!"); |
|
361 |
} else { |
|
362 |
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias(); -> Section: section.getTitle(); |
|
363 |
throw new PathNotValidException("Toggle indicators: Indicator with id: "+indicator.getId()+" not found in Section: "+sectionId); |
|
364 |
} |
|
365 |
|
|
366 |
} |
|
367 |
|
|
368 |
private Section checkForExceptions(String stakeholderId, String topicId, String categoryId, String subcategoryId, String sectionId, String indicatorType) { |
|
369 |
|
|
551 | 370 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
552 | 371 |
|
553 |
if (stakeholder != null) { |
|
372 |
if(stakeholder == null) { |
|
373 |
// EXCEPTION - Stakeholder not found |
|
374 |
throw new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " not found"); |
|
375 |
} |
|
554 | 376 |
|
555 |
Topic<String> topic = topicDAO.findById(topicId); |
|
556 |
if (topic != null) { |
|
557 |
if (stakeholder.getTopics().contains(topicId)) { |
|
377 |
Topic<String> topic = topicDAO.findById(topicId); |
|
378 |
if(topic == null) { |
|
379 |
// EXCEPTION - Topic not found |
|
380 |
throw new EntityNotFoundException("Save indicator: Topic with id: "+topicId+" not found"); |
|
381 |
} |
|
558 | 382 |
|
559 |
Category<String> category = categoryDAO.findById(categoryId); |
|
560 |
if (category != null) { |
|
561 |
if (topic.getCategories().contains(categoryId)) { |
|
383 |
if(!stakeholder.getTopics().contains(topicId)) { |
|
384 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
385 |
throw new PathNotValidException("Save indicator: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId); |
|
386 |
} |
|
562 | 387 |
|
563 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
564 |
if (subcategory != null) { |
|
565 |
if (category.getSubCategories().contains(subcategoryId)) { |
|
566 |
List<String> indicators = null; |
|
567 |
if(indicator.getType().equals("chart")) { |
|
568 |
indicators = subcategory.getCharts(); |
|
569 |
} else if(indicator.getType().equals("number")) { |
|
570 |
indicators = subcategory.getNumbers(); |
|
571 |
} |
|
388 |
Category<String> category = categoryDAO.findById(categoryId); |
|
389 |
if(category == null) { |
|
390 |
// EXCEPTION - Category not found |
|
391 |
throw new EntityNotFoundException("Save indicator: Category with id: "+categoryId+" not found"); |
|
392 |
} |
|
572 | 393 |
|
573 |
if(indicators.contains(indicator.getId())) { |
|
574 |
indicatorDAO.save(indicator); |
|
575 |
log.debug("Indicator toggled!"); |
|
576 |
} else { |
|
577 |
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias(); |
|
578 |
throw new PathNotValidException("Toggle indicators: Indicator with id: "+indicator.getId()+" not found in SubCategory: "+subcategoryId); |
|
579 |
} |
|
580 |
} else { |
|
581 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
582 |
throw new PathNotValidException("Toggle indicators: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
583 |
} |
|
584 |
} else { |
|
585 |
// EXCEPTION - SubCategory not found |
|
586 |
throw new EntityNotFoundException("Toggle indicators: SubCategory with id: "+subcategoryId+" not found"); |
|
587 |
} |
|
588 |
} else { |
|
589 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
590 |
throw new PathNotValidException("Toggle indicators: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
591 |
} |
|
592 |
} else { |
|
593 |
// EXCEPTION - Category not found |
|
594 |
throw new EntityNotFoundException("Toggle indicators: Category with id: "+categoryId+" not found"); |
|
595 |
} |
|
596 |
} else { |
|
597 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
598 |
throw new PathNotValidException("Toggle indicators: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
599 |
} |
|
600 |
} else { |
|
601 |
// EXCEPTION - Topic not found |
|
602 |
throw new EntityNotFoundException("Toggle indicators: Topic with id: "+topicId+" not found"); |
|
394 |
if(!topic.getCategories().contains(categoryId)) { |
|
395 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
396 |
throw new PathNotValidException("Save indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
397 |
} |
|
398 |
|
|
399 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
400 |
if(subcategory == null) { |
|
401 |
// EXCEPTION - SubCategory not found |
|
402 |
throw new EntityNotFoundException("Save indicator: SubCategory with id: "+subcategoryId+" not found"); |
|
403 |
} |
|
404 |
|
|
405 |
if (!category.getSubCategories().contains(subcategoryId)) { |
|
406 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
407 |
throw new PathNotValidException("Save indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
408 |
} |
|
409 |
|
|
410 |
Section<String> section = sectionDAO.findById(sectionId); |
|
411 |
if(section == null) { |
|
412 |
// EXCEPTION - Section not found |
|
413 |
throw new EntityNotFoundException("Save indicator: Section with id: "+sectionId+" not found"); |
|
414 |
} |
|
415 |
|
|
416 |
if(indicatorType.equals("chart")) { |
|
417 |
if (!subcategory.getCharts().contains(sectionId)) { |
|
418 |
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); |
|
419 |
throw new PathNotValidException("Save indicator: SubCategory with id: " + subcategoryId + " not found in Category: " + categoryId); |
|
603 | 420 |
} |
604 |
} else { |
|
605 |
// EXCEPTION - Stakeholder not found |
|
606 |
throw new EntityNotFoundException("Toggle indicators: Stakeholder with id: "+stakeholderId+" not found"); |
|
421 |
} else if(indicatorType.equals("number")) { |
|
422 |
if (!subcategory.getNumbers().contains(sectionId)) { |
|
423 |
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); |
|
424 |
throw new PathNotValidException("Save indicator: SubCategory with id: " + subcategoryId + " not found in Category: " + categoryId); |
|
425 |
} |
|
607 | 426 |
} |
427 |
|
|
428 |
return section; |
|
608 | 429 |
} |
609 | 430 |
} |
Also available in: Unified diff
[Trunk | Monitor Service]:
1. Section entity level added. Hierarchy changed from: Stakeholder > Topic > Category > SubCategory > Indicator to: Stakeholder > Topic > Category > SubCategory > Section > Indicator.
2. Section.java & SectionDAO.java & MongoDBSectionDAO.java & SectionController.java: New entity 'Section', DAOs for Section, Controller for section added.
3. In all controllers fix hierarchy of model to include Section.
4. SubCategoryController.java & IndicatorController.java: Helper method 'checkForExceptions()' added (instead of checking in every method separately).