Revision 58978
Added by Konstantina Galouni almost 4 years ago
IndicatorController.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import java.io.UnsupportedEncodingException; |
13 | 13 |
import java.net.URLEncoder; |
14 |
import java.util.ArrayList; |
|
15 |
import java.util.HashMap; |
|
16 |
import java.util.List; |
|
17 |
import java.util.Map; |
|
14 |
import java.util.*; |
|
18 | 15 |
|
19 | 16 |
@RestController |
20 | 17 |
@CrossOrigin(origins = "*") |
... | ... | |
146 | 143 |
|
147 | 144 |
// Check if there are changes in indicator path and update existing indicators if needed |
148 | 145 |
log.debug("update indicator path: "+i); |
149 |
log.debug("indicatorPath.getType(): "+indicatorPath.getType()); |
|
150 |
log.debug("indicatorPathBasedOnDefault.getType(): "+indicatorPathBasedOnDefault.getType()); |
|
151 |
log.debug("oldIndicatorPath.getType(): "+oldIndicatorPath.getType()); |
|
152 | 146 |
|
153 | 147 |
if(indicatorPath.getType() != null |
154 | 148 |
&& !indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()) |
... | ... | |
311 | 305 |
@PathVariable("categoryId") String categoryId, |
312 | 306 |
@PathVariable("subcategoryId") String subcategoryId, |
313 | 307 |
@PathVariable("sectionId") String sectionId, |
314 |
@PathVariable("indicatorId") String indicatorId) { |
|
308 |
@PathVariable("indicatorId") String indicatorId, |
|
309 |
@RequestParam(required = false) String children) { |
|
315 | 310 |
log.debug("delete indicator"); |
316 | 311 |
log.debug("Id: "+indicatorId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId); |
317 | 312 |
|
... | ... | |
323 | 318 |
|
324 | 319 |
int index = indicators.indexOf(indicatorId); |
325 | 320 |
if (index != -1) { |
321 |
|
|
322 |
// this indicator belongs in default profile |
|
323 |
if(section.getDefaultId() == null && children != null) { |
|
324 |
onDeleteDefaultIndicator(indicatorId, sectionId, children); |
|
325 |
} |
|
326 |
|
|
327 |
|
|
326 | 328 |
indicators.remove(index); |
327 | 329 |
sectionDAO.save(section); |
328 | 330 |
|
... | ... | |
339 | 341 |
return true; |
340 | 342 |
} |
341 | 343 |
|
344 |
public boolean onDeleteDefaultIndicator(String defaultIndicatorId, String defaultSectionId, String children) { |
|
345 |
if(children.equals("delete")) { |
|
346 |
// // 1st way |
|
347 |
// List<Section> sections = sectionDAO.findByDefaultId(defaultSectionId); |
|
348 |
// |
|
349 |
// for(Section section : sections) { |
|
350 |
// List<String> indicators = section.getIndicators(); |
|
351 |
// |
|
352 |
// Iterator<String> indicatorsIterator = indicators.iterator(); |
|
353 |
// while(indicatorsIterator.hasNext()) { |
|
354 |
// String indicatorId = indicatorsIterator.next(); |
|
355 |
// |
|
356 |
// Indicator indicator = indicatorDAO.findById(indicatorId); |
|
357 |
// if (indicator.getDefaultId().equals(defaultIndicatorId)) { |
|
358 |
// indicatorsIterator.remove(); |
|
359 |
// sectionDAO.save(section); |
|
360 |
// |
|
361 |
// indicatorDAO.delete(indicatorId); |
|
362 |
// log.debug("Indicator deleted!"); |
|
363 |
// |
|
364 |
// break; |
|
365 |
// } |
|
366 |
// } |
|
367 |
// } |
|
368 |
|
|
369 |
// 2nd way |
|
370 |
List<Section> sections = sectionDAO.findByDefaultId(defaultSectionId); |
|
371 |
List<Indicator> indicators = indicatorDAO.findByDefaultId(defaultIndicatorId); |
|
372 |
|
|
373 |
for(Section section : sections) { |
|
374 |
Iterator<Indicator> indicatorsIterator = indicators.iterator(); |
|
375 |
while(indicatorsIterator.hasNext()) { |
|
376 |
String indicatorId = indicatorsIterator.next().getId(); |
|
377 |
if(section.getIndicators().contains(indicatorId)) { |
|
378 |
indicatorsIterator.remove(); |
|
379 |
|
|
380 |
section.getIndicators().remove(indicatorId); |
|
381 |
sectionDAO.save(section); |
|
382 |
|
|
383 |
indicatorDAO.delete(indicatorId); |
|
384 |
log.debug("Indicator with id: "+indicatorId+" deleted!"); |
|
385 |
|
|
386 |
break; |
|
387 |
} |
|
388 |
} |
|
389 |
} |
|
390 |
|
|
391 |
// // 3rd way - parentId |
|
392 |
// List<Indicator> indicators = indicatorDAO.findByDefaultId(defaultIndicatorId); |
|
393 |
// for(Indicator indicator : indicators) { |
|
394 |
// Section section = sectionDAO.findById(indicator.getParent()); |
|
395 |
// List<String> sectionIndicators = section.getIndicators(); |
|
396 |
// |
|
397 |
// sectionIndicators.remove(indicator.getId()); |
|
398 |
// sectionDAO.save(section); |
|
399 |
// |
|
400 |
// indicatorDAO.delete(indicator.getId()); |
|
401 |
// log.debug("Indicator deleted!"); |
|
402 |
// } |
|
403 |
} else if(children.equals("disconnect")) { |
|
404 |
List<Indicator> indicators = indicatorDAO.findByDefaultId(defaultIndicatorId); |
|
405 |
for(Indicator indicator : indicators) { |
|
406 |
indicator.setDefaultId(null); |
|
407 |
indicatorDAO.save(indicator); |
|
408 |
log.debug("DefaultId for Indicator with id: "+indicator.getId()+" empty!"); |
|
409 |
} |
|
410 |
} |
|
411 |
return true; |
|
412 |
} |
|
413 |
|
|
342 | 414 |
// @RequestMapping(value = "/{stakeholderId}/charts/delete", method = RequestMethod.DELETE) |
343 | 415 |
// public boolean deleteAllChartIndicators(@PathVariable("stakeholderId") String stakeholderId) { |
344 | 416 |
// log.debug("delete all chart indicators of stakeholder"); |
... | ... | |
557 | 629 |
|
558 | 630 |
return section; |
559 | 631 |
} |
632 |
|
|
633 |
public void deleteTree(Section section) { |
|
634 |
List<String> indicators = section.getIndicators(); |
|
635 |
for(String indicatorId : indicators) { |
|
636 |
indicatorDAO.delete(indicatorId); |
|
637 |
} |
|
638 |
} |
|
639 |
|
|
640 |
public void disConnectTree(Section section) { |
|
641 |
List<String> indicators = section.getIndicators(); |
|
642 |
for(String indicatorId : indicators) { |
|
643 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
|
644 |
indicator.setDefaultId(null); |
|
645 |
indicatorDAO.save(indicator); |
|
646 |
} |
|
647 |
} |
|
560 | 648 |
} |
Also available in: Unified diff
[Trunk | Monitor Service]:
1. Adding parameter in delete methods to delete or disconnect all profiles based on the default one that is being deleted (not for stakeholder).
2. In delete methods remove iterations (for deleting inner elements) and call "deleteTree()" method.