1
|
package eu.dnetlib.uoamonitorservice.controllers;
|
2
|
|
3
|
import eu.dnetlib.uoamonitorservice.dao.*;
|
4
|
import eu.dnetlib.uoamonitorservice.entities.*;
|
5
|
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
|
6
|
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
|
7
|
import eu.dnetlib.uoamonitorservice.handlers.utils.RolesUtils;
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.springframework.beans.factory.annotation.Autowired;
|
10
|
import org.springframework.security.access.AccessDeniedException;
|
11
|
import org.springframework.security.access.prepost.PreAuthorize;
|
12
|
import org.springframework.web.bind.annotation.*;
|
13
|
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.Date;
|
16
|
import java.util.Iterator;
|
17
|
import java.util.List;
|
18
|
|
19
|
@RestController
|
20
|
@CrossOrigin(origins = "*")
|
21
|
public class SectionController {
|
22
|
private final Logger log = Logger.getLogger(this.getClass());
|
23
|
|
24
|
@Autowired
|
25
|
private RolesUtils rolesUtils;
|
26
|
|
27
|
@Autowired
|
28
|
private StakeholderDAO stakeholderDAO;
|
29
|
|
30
|
@Autowired
|
31
|
private TopicDAO topicDAO;
|
32
|
|
33
|
@Autowired
|
34
|
private CategoryDAO categoryDAO;
|
35
|
|
36
|
@Autowired
|
37
|
private SubCategoryDAO subCategoryDAO;
|
38
|
|
39
|
@Autowired
|
40
|
private SectionDAO sectionDAO;
|
41
|
|
42
|
@Autowired
|
43
|
private IndicatorDAO indicatorDAO;
|
44
|
|
45
|
@Autowired
|
46
|
private IndicatorController indicatorController;
|
47
|
|
48
|
public Section<Indicator> buildSection(Section<Indicator> sectionFull) {
|
49
|
Section<String> section = new Section<>(sectionFull);
|
50
|
|
51
|
List<String> indicators = new ArrayList<>();
|
52
|
List<Indicator> indicatorsFull = new ArrayList<>();
|
53
|
for(Indicator chart : sectionFull.getIndicators()) {
|
54
|
Indicator chartSaved = indicatorDAO.save(chart);
|
55
|
chart.setId(chartSaved.getId());
|
56
|
indicatorsFull.add(chart);
|
57
|
indicators.add(chartSaved.getId());
|
58
|
}
|
59
|
sectionFull.setIndicators(indicatorsFull);
|
60
|
section.setIndicators(indicators);
|
61
|
|
62
|
Date date = new Date();
|
63
|
section.setCreationDate(date);
|
64
|
section.setUpdateDate(date);
|
65
|
|
66
|
sectionFull.setCreationDate(date);
|
67
|
sectionFull.setUpdateDate(date);
|
68
|
|
69
|
sectionDAO.save(section);
|
70
|
|
71
|
sectionFull.setId(section.getId());
|
72
|
return sectionFull;
|
73
|
}
|
74
|
|
75
|
@PreAuthorize("isAuthenticated()")
|
76
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save/{index}", method = RequestMethod.POST)
|
77
|
public Section saveSection(@PathVariable("stakeholderId") String stakeholderId,
|
78
|
@PathVariable("topicId") String topicId,
|
79
|
@PathVariable("categoryId") String categoryId,
|
80
|
@PathVariable("subcategoryId") String subcategoryId,
|
81
|
@PathVariable("index") String index,
|
82
|
@RequestBody Section<Indicator> sectionFull) {
|
83
|
log.debug("save section");
|
84
|
log.debug("Name: "+sectionFull.getTitle() + " - Id: "+sectionFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
|
85
|
|
86
|
SubCategory<String> subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId);
|
87
|
|
88
|
Section<String> section = new Section<>(sectionFull);
|
89
|
|
90
|
Date date = new Date();
|
91
|
section.setUpdateDate(date);
|
92
|
sectionFull.setUpdateDate(date);
|
93
|
|
94
|
Section<String> oldSection = null;
|
95
|
if(sectionFull.getId() != null) {
|
96
|
oldSection = sectionDAO.findById(sectionFull.getId());
|
97
|
} else { // section does not exist in DB
|
98
|
section.setCreationDate(date);
|
99
|
sectionFull.setCreationDate(date);
|
100
|
}
|
101
|
|
102
|
String sectionId = sectionFull.getId();
|
103
|
List<String> indicators = new ArrayList<>();
|
104
|
for(Indicator indicator : sectionFull.getIndicators()) {
|
105
|
indicators.add(indicator.getId());
|
106
|
}
|
107
|
section.setIndicators(indicators);
|
108
|
|
109
|
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
|
110
|
// this section belongs in default profile and it is new or it is updated
|
111
|
if(stakeholder.getDefaultId() == null) {
|
112
|
if(sectionId == null) {
|
113
|
sectionDAO.save(section);
|
114
|
onSaveDefaultSection(section, topicId, categoryId, subcategoryId, stakeholder);
|
115
|
}
|
116
|
else {
|
117
|
onUpdateDefaultSection(section, stakeholder, oldSection);
|
118
|
sectionDAO.save(section);
|
119
|
}
|
120
|
} else {
|
121
|
sectionDAO.save(section);
|
122
|
}
|
123
|
|
124
|
List<String> sections = null;
|
125
|
if(sectionFull.getType().equals("chart")) {
|
126
|
sections = subCategory.getCharts();
|
127
|
} else if(sectionFull.getType().equals("number")) {
|
128
|
sections = subCategory.getNumbers();
|
129
|
}
|
130
|
|
131
|
int existing_index = sections.indexOf(section.getId());
|
132
|
if (existing_index == -1) {
|
133
|
if(Integer.parseInt(index) != -1) {
|
134
|
sections.add(Integer.parseInt(index), section.getId());
|
135
|
} else {
|
136
|
sections.add(section.getId());
|
137
|
}
|
138
|
subCategoryDAO.save(subCategory);
|
139
|
log.debug("Section saved!");
|
140
|
|
141
|
sectionFull.setId(section.getId());
|
142
|
}
|
143
|
|
144
|
return sectionFull;
|
145
|
}
|
146
|
|
147
|
public void onSaveDefaultSection(Section section,
|
148
|
String defaultTopicId, String defaultCategoryId,
|
149
|
String defaultSubcategoryId, Stakeholder defaultStakeholder) {
|
150
|
log.debug("On save default section");
|
151
|
|
152
|
|
153
|
// new section in default profile - add it on profiles of the same type
|
154
|
List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubcategoryId);
|
155
|
|
156
|
for (SubCategory subCategory : subCategories) {
|
157
|
Category parentCategory = categoryDAO.findBySubCategoriesContaining(subCategory.getId());
|
158
|
Topic parentTopic = topicDAO.findByCategoriesContaining(parentCategory.getId());
|
159
|
Stakeholder parentStakeholder = stakeholderDAO.findByTopicsContaining(parentTopic.getId());
|
160
|
|
161
|
Section sectionNew = new Section();
|
162
|
sectionNew.copyFromDefault(section);
|
163
|
|
164
|
sectionNew.setStakeholderAlias(parentStakeholder.getAlias());
|
165
|
|
166
|
sectionDAO.save(sectionNew);
|
167
|
|
168
|
List<String> sections = null;
|
169
|
if (section.getType().equals("chart")) {
|
170
|
sections = subCategory.getCharts();
|
171
|
} else if (section.getType().equals("number")) {
|
172
|
sections = subCategory.getNumbers();
|
173
|
}
|
174
|
sections.add(sectionNew.getId());
|
175
|
|
176
|
subCategoryDAO.save(subCategory);
|
177
|
}
|
178
|
}
|
179
|
|
180
|
public void onUpdateDefaultSection(Section section, Stakeholder stakeholder, Section oldSection) {
|
181
|
log.debug("On update default section");
|
182
|
|
183
|
// section already exists - check if changed and update all sections based on it
|
184
|
|
185
|
boolean changed = false;
|
186
|
List<Section> sections = sectionDAO.findByDefaultId(section.getId());
|
187
|
|
188
|
for(Section sectionBasedOnDefault : sections) {
|
189
|
if(section.getTitle() != null && !section.getTitle().equals(sectionBasedOnDefault.getTitle())
|
190
|
&& (oldSection.getTitle() == null || oldSection.getTitle().equals(sectionBasedOnDefault.getTitle()))) {
|
191
|
|
192
|
sectionBasedOnDefault.setTitle(section.getTitle());
|
193
|
changed = true;
|
194
|
}
|
195
|
|
196
|
if(!changed) {
|
197
|
// break;
|
198
|
continue;
|
199
|
}
|
200
|
|
201
|
// sectionBasedOnDefault.setTitle(section.getTitle());
|
202
|
sectionBasedOnDefault.setUpdateDate(section.getUpdateDate());
|
203
|
sectionDAO.save(sectionBasedOnDefault);
|
204
|
}
|
205
|
}
|
206
|
|
207
|
@PreAuthorize("isAuthenticated()")
|
208
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/delete", method = RequestMethod.DELETE)
|
209
|
public boolean deleteSection(@PathVariable("stakeholderId") String stakeholderId,
|
210
|
@PathVariable("topicId") String topicId,
|
211
|
@PathVariable("categoryId") String categoryId,
|
212
|
@PathVariable("subcategoryId") String subcategoryId,
|
213
|
@PathVariable("sectionId") String sectionId,
|
214
|
@RequestParam(required = false) String children) {
|
215
|
log.debug("delete section");
|
216
|
log.debug("Id: "+sectionId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
|
217
|
|
218
|
Section section = sectionDAO.findById(sectionId);
|
219
|
if(section != null) {
|
220
|
SubCategory<String> subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId);
|
221
|
|
222
|
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
|
223
|
List<String> roles = rolesUtils.getRoles();
|
224
|
if(section.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(roles, stakeholder.getType())) {
|
225
|
// EXCEPTION - Access denied
|
226
|
throw new AccessDeniedException("Delete section: You are not authorized to delete a default Section in stakeholder with id: "+stakeholderId);
|
227
|
}
|
228
|
|
229
|
String type = "";
|
230
|
List<String> sections = null;
|
231
|
if (section.getType().equals("chart")) {
|
232
|
sections = subCategory.getCharts();
|
233
|
type = "chart";
|
234
|
} else if (section.getType().equals("number")) {
|
235
|
sections = subCategory.getNumbers();
|
236
|
type = "number";
|
237
|
}
|
238
|
|
239
|
int index = sections.indexOf(sectionId);
|
240
|
if (index != -1) {
|
241
|
// this section belongs in default profile
|
242
|
if(subCategory.getDefaultId() == null && children != null) {
|
243
|
onDeleteDefaultSection(sectionId, subcategoryId, children, type);
|
244
|
}
|
245
|
|
246
|
indicatorController.deleteTree(section);
|
247
|
|
248
|
sections.remove(index);
|
249
|
subCategoryDAO.save(subCategory);
|
250
|
|
251
|
sectionDAO.delete(sectionId);
|
252
|
log.debug("Section deleted!");
|
253
|
} else {
|
254
|
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias();
|
255
|
throw new PathNotValidException("Delete section: Section with id: "+sectionId+" not found in SubCategory: "+subcategoryId);
|
256
|
}
|
257
|
} else {
|
258
|
// EXCEPTION - Section not found
|
259
|
throw new EntityNotFoundException("Delete section: Section with id: "+sectionId+" not found");
|
260
|
}
|
261
|
return true;
|
262
|
}
|
263
|
|
264
|
public boolean onDeleteDefaultSection(String defaultSectionId, String defaultSubCategoryId, String children, String type) {
|
265
|
if(children.equals("delete")) {
|
266
|
List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubCategoryId);
|
267
|
List<Section> sections = sectionDAO.findByDefaultId(defaultSectionId);
|
268
|
|
269
|
for(SubCategory subCategory : subCategories) {
|
270
|
Iterator<Section> sectionsIterator = sections.iterator();
|
271
|
while(sectionsIterator.hasNext()) {
|
272
|
Section section = sectionsIterator.next();
|
273
|
|
274
|
String sectionId = section.getId();
|
275
|
List<String> subCategorySections = null;
|
276
|
if(type.equals("chart")) {
|
277
|
subCategorySections = subCategory.getCharts();
|
278
|
} else if(type.equals("number")) {
|
279
|
subCategorySections = subCategory.getNumbers();
|
280
|
}
|
281
|
if(subCategorySections != null && subCategorySections.contains(sectionId)) {
|
282
|
sectionsIterator.remove();
|
283
|
|
284
|
subCategorySections.remove(sectionId);
|
285
|
subCategoryDAO.save(subCategory);
|
286
|
|
287
|
indicatorController.deleteTree(section);
|
288
|
|
289
|
sectionDAO.delete(sectionId);
|
290
|
log.debug("Section with id: "+sectionId+" deleted!");
|
291
|
|
292
|
break;
|
293
|
}
|
294
|
}
|
295
|
}
|
296
|
} else if(children.equals("disconnect")) {
|
297
|
List<Section> sections = sectionDAO.findByDefaultId(defaultSectionId);
|
298
|
for(Section section : sections) {
|
299
|
indicatorController.disConnectTree(section);
|
300
|
|
301
|
section.setDefaultId(null);
|
302
|
sectionDAO.save(section);
|
303
|
|
304
|
log.debug("DefaultId for Section with id: "+section.getId()+" empty!");
|
305
|
}
|
306
|
}
|
307
|
return true;
|
308
|
}
|
309
|
|
310
|
@PreAuthorize("isAuthenticated()")
|
311
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder", method = RequestMethod.POST)
|
312
|
public List<Section> reorderSections(@PathVariable("stakeholderId") String stakeholderId,
|
313
|
@PathVariable("topicId") String topicId,
|
314
|
@PathVariable("categoryId") String categoryId,
|
315
|
@PathVariable("subcategoryId") String subcategoryId,
|
316
|
@PathVariable("type") String type,
|
317
|
@RequestBody List<String> sections) {
|
318
|
log.debug("reorder sections of type: "+type);
|
319
|
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
|
320
|
|
321
|
SubCategory<String> subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId);
|
322
|
|
323
|
if (type.equals("chart")) {
|
324
|
subCategory.setCharts(sections);
|
325
|
} else if (type.equals("number")) {
|
326
|
subCategory.setNumbers(sections);
|
327
|
}
|
328
|
|
329
|
subCategoryDAO.save(subCategory);
|
330
|
log.debug("Sections reordered!");
|
331
|
|
332
|
List<Section> sectionsFull = new ArrayList<>();
|
333
|
for(String sectionId : sections) {
|
334
|
sectionsFull.add(sectionDAO.findById(sectionId));
|
335
|
}
|
336
|
return sectionsFull;
|
337
|
}
|
338
|
|
339
|
// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/toggle-status", method = RequestMethod.POST)
|
340
|
// public Boolean toggleSectionStatus(@PathVariable("stakeholderId") String stakeholderId,
|
341
|
// @PathVariable("topicId") String topicId,
|
342
|
// @PathVariable("categoryId") String categoryId,
|
343
|
// @PathVariable("subcategoryId") String subcategoryId,
|
344
|
// @PathVariable("sectionId") String sectionId) {
|
345
|
// log.debug("toggle section status (isActive)");
|
346
|
// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Section: "+sectionId);
|
347
|
//
|
348
|
// Section section = sectionDAO.findById(sectionId);
|
349
|
// if (section == null) {
|
350
|
// // EXCEPTION - Section not found
|
351
|
// throw new EntityNotFoundException("Toggle section status: Section with id: "+sectionId+" not found");
|
352
|
// }
|
353
|
// section.setIsActive(!section.getIsActive());
|
354
|
//
|
355
|
// this.toggleSection(stakeholderId, topicId, categoryId, subcategoryId, section);
|
356
|
//
|
357
|
// return section.getIsActive();
|
358
|
// }
|
359
|
|
360
|
// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/toggle-access", method = RequestMethod.POST)
|
361
|
// public Boolean toggleSectionAccess(@PathVariable("stakeholderId") String stakeholderId,
|
362
|
// @PathVariable("topicId") String topicId,
|
363
|
// @PathVariable("categoryId") String categoryId,
|
364
|
// @PathVariable("subcategoryId") String subcategoryId,
|
365
|
// @PathVariable("sectionId") String sectionId) {
|
366
|
// log.debug("toggle section access (isPublic)");
|
367
|
// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
|
368
|
//
|
369
|
// Section section = sectionDAO.findById(sectionId);
|
370
|
// if (section == null) {
|
371
|
// // EXCEPTION - Section not found
|
372
|
// throw new EntityNotFoundException("Toggle section access: Section with id: "+sectionId+" not found");
|
373
|
// }
|
374
|
// section.setIsPublic(!section.getIsPublic());
|
375
|
//
|
376
|
// this.toggleSection(stakeholderId, topicId, categoryId, subcategoryId);
|
377
|
//
|
378
|
// return section.getIsPublic();
|
379
|
// }
|
380
|
|
381
|
|
382
|
public void toggleSection(String stakeholderId, String topicId, String categoryId, String subcategoryId, Section section) {
|
383
|
SubCategory<String> subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId);
|
384
|
|
385
|
List<String> sections = null;
|
386
|
if (section.getType().equals("chart")) {
|
387
|
sections = subCategory.getCharts();
|
388
|
} else if (section.getType().equals("number")) {
|
389
|
sections = subCategory.getNumbers();
|
390
|
}
|
391
|
|
392
|
if(sections.contains(section.getId())) {
|
393
|
sectionDAO.save(section);
|
394
|
log.debug("Section toggled!");
|
395
|
} else {
|
396
|
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias();
|
397
|
throw new PathNotValidException("Toggle section: Section with id: "+section.getId()+" not found in SubCategory: "+subcategoryId);
|
398
|
}
|
399
|
|
400
|
}
|
401
|
|
402
|
private SubCategory checkForExceptions(String stakeholderId, String topicId, String categoryId, String subcategoryId) {
|
403
|
|
404
|
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
|
405
|
|
406
|
if(stakeholder == null) {
|
407
|
// EXCEPTION - Stakeholder not found
|
408
|
throw new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " not found");
|
409
|
}
|
410
|
|
411
|
List<String> roles = rolesUtils.getRoles();
|
412
|
if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) {
|
413
|
// EXCEPTION - Access denied
|
414
|
throw new AccessDeniedException("CheckForExceptions Section: You are not authorized to update stakeholder with id: "+stakeholderId);
|
415
|
}
|
416
|
|
417
|
Topic<String> topic = topicDAO.findById(topicId);
|
418
|
if(topic == null) {
|
419
|
// EXCEPTION - Topic not found
|
420
|
throw new EntityNotFoundException("Save indicator: Topic with id: "+topicId+" not found");
|
421
|
}
|
422
|
|
423
|
if(!stakeholder.getTopics().contains(topicId)) {
|
424
|
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
|
425
|
throw new PathNotValidException("Save indicator: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId);
|
426
|
}
|
427
|
|
428
|
Category<String> category = categoryDAO.findById(categoryId);
|
429
|
if(category == null) {
|
430
|
// EXCEPTION - Category not found
|
431
|
throw new EntityNotFoundException("Save indicator: Category with id: "+categoryId+" not found");
|
432
|
}
|
433
|
|
434
|
if(!topic.getCategories().contains(categoryId)) {
|
435
|
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
|
436
|
throw new PathNotValidException("Save indicator: Category with id: "+categoryId+" not found in Topic: "+topicId);
|
437
|
}
|
438
|
|
439
|
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
|
440
|
if(subcategory == null) {
|
441
|
// EXCEPTION - SubCategory not found
|
442
|
throw new EntityNotFoundException("Save indicator: SubCategory with id: "+subcategoryId+" not found");
|
443
|
}
|
444
|
|
445
|
if (!category.getSubCategories().contains(subcategoryId)) {
|
446
|
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
|
447
|
throw new PathNotValidException("Save indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
|
448
|
}
|
449
|
|
450
|
return subcategory;
|
451
|
}
|
452
|
|
453
|
public void deleteTree(SubCategory subCategory) {
|
454
|
List<String> sections = subCategory.getCharts();
|
455
|
for(String sectionId : sections) {
|
456
|
Section section = sectionDAO.findById(sectionId);
|
457
|
if (section == null) {
|
458
|
// EXCEPTION - Section not found
|
459
|
throw new EntityNotFoundException("Section delete tree: Chart Section with id: "+sectionId+" not found (section exists in subCategory: "+subCategory.getId()+")");
|
460
|
}
|
461
|
|
462
|
indicatorController.deleteTree(section);
|
463
|
|
464
|
sectionDAO.delete(sectionId);
|
465
|
}
|
466
|
|
467
|
sections = subCategory.getNumbers();
|
468
|
for(String sectionId : sections) {
|
469
|
Section section = sectionDAO.findById(sectionId);
|
470
|
if (section == null) {
|
471
|
// EXCEPTION - Section not found
|
472
|
throw new EntityNotFoundException("Section delete tree: Number Section with id: "+sectionId+" not found (section exists in subCategory: "+subCategory.getId()+")");
|
473
|
}
|
474
|
|
475
|
indicatorController.deleteTree(section);
|
476
|
|
477
|
sectionDAO.delete(sectionId);
|
478
|
}
|
479
|
}
|
480
|
|
481
|
public void disConnectTree(SubCategory subCategory) {
|
482
|
List<String> sections = subCategory.getCharts();
|
483
|
for(String sectionId : sections) {
|
484
|
Section section = sectionDAO.findById(sectionId);
|
485
|
if (section == null) {
|
486
|
// EXCEPTION - Section not found
|
487
|
throw new EntityNotFoundException("Section disconnect tree: Chart Section with id: "+sectionId+" not found (section exists in subCategory: "+subCategory.getId()+")");
|
488
|
}
|
489
|
|
490
|
indicatorController.disConnectTree(section);
|
491
|
|
492
|
section.setDefaultId(null);
|
493
|
sectionDAO.save(section);
|
494
|
}
|
495
|
|
496
|
sections = subCategory.getNumbers();
|
497
|
for(String sectionId : sections) {
|
498
|
Section section = sectionDAO.findById(sectionId);
|
499
|
if (section == null) {
|
500
|
// EXCEPTION - Section not found
|
501
|
throw new EntityNotFoundException("Section disconnect tree: Number Section with id: "+sectionId+" not found (section exists in subCategory: "+subCategory.getId()+")");
|
502
|
}
|
503
|
|
504
|
indicatorController.disConnectTree(section);
|
505
|
|
506
|
section.setDefaultId(null);
|
507
|
sectionDAO.save(section);
|
508
|
}
|
509
|
}
|
510
|
}
|