1
|
package eu.dnetlib.uoamonitorservice.controllers;
|
2
|
|
3
|
|
4
|
import eu.dnetlib.uoamonitorservice.dao.*;
|
5
|
import eu.dnetlib.uoamonitorservice.entities.*;
|
6
|
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
|
7
|
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.springframework.beans.factory.annotation.Autowired;
|
10
|
import org.springframework.web.bind.annotation.*;
|
11
|
|
12
|
import java.io.UnsupportedEncodingException;
|
13
|
import java.net.URLEncoder;
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.List;
|
16
|
import java.util.Map;
|
17
|
|
18
|
@RestController
|
19
|
@CrossOrigin(origins = "*")
|
20
|
public class IndicatorController {
|
21
|
private final Logger log = Logger.getLogger(this.getClass());
|
22
|
|
23
|
@Autowired
|
24
|
private StakeholderDAO stakeholderDAO;
|
25
|
|
26
|
@Autowired
|
27
|
private TopicDAO topicDAO;
|
28
|
|
29
|
@Autowired
|
30
|
private CategoryDAO categoryDAO;
|
31
|
|
32
|
@Autowired
|
33
|
private SubCategoryDAO subCategoryDAO;
|
34
|
|
35
|
@Autowired
|
36
|
private SectionDAO sectionDAO;
|
37
|
|
38
|
@Autowired
|
39
|
private IndicatorDAO indicatorDAO;
|
40
|
|
41
|
|
42
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/save", method = RequestMethod.POST)
|
43
|
public Indicator saveIndicator(@PathVariable("stakeholderId") String stakeholderId,
|
44
|
@PathVariable("topicId") String topicId,
|
45
|
@PathVariable("categoryId") String categoryId,
|
46
|
@PathVariable("subcategoryId") String subcategoryId,
|
47
|
@PathVariable("sectionId") String sectionId,
|
48
|
@RequestBody Indicator indicator) throws UnsupportedEncodingException {
|
49
|
log.debug("save indicator");
|
50
|
log.debug("Name: "+indicator.getName() + " - Id: "+indicator.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
|
51
|
|
52
|
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
|
53
|
|
54
|
String indicatorId = indicator.getId();
|
55
|
indicatorDAO.save(indicator);
|
56
|
|
57
|
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
|
58
|
// this indicator belongs in default profile and it is new or it is updated
|
59
|
if(stakeholder.getDefaultId() == null) {
|
60
|
if(indicatorId == null) {
|
61
|
onSaveDefaultIndicator(indicator, sectionId);
|
62
|
}
|
63
|
else {
|
64
|
onUpdateDefaultIndicator(indicator, stakeholder);
|
65
|
}
|
66
|
}
|
67
|
|
68
|
List<String> indicators = section.getIndicators();
|
69
|
|
70
|
int index = indicators.indexOf(indicator.getId());
|
71
|
if (index == -1) {
|
72
|
indicators.add(indicator.getId());
|
73
|
sectionDAO.save(section);
|
74
|
log.debug("Indicator saved!");
|
75
|
}
|
76
|
|
77
|
return indicator;
|
78
|
}
|
79
|
|
80
|
public void onSaveDefaultIndicator(Indicator indicator, String defaultSectionId) throws UnsupportedEncodingException {
|
81
|
log.debug("On save default indicator");
|
82
|
|
83
|
// new indicator in default profile - add it on profiles of the same type
|
84
|
List<Section> sections = sectionDAO.findByDefaultId(defaultSectionId);
|
85
|
|
86
|
for (Section section : sections) {
|
87
|
Indicator indicatorNew = new Indicator();
|
88
|
indicatorNew.copyFromDefault(indicator);
|
89
|
for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) {
|
90
|
Stakeholder stakeholder = stakeholderDAO.findByAlias(section.getStakeholderAlias());
|
91
|
parameterMapping(indicatorPath, stakeholder);
|
92
|
}
|
93
|
|
94
|
indicatorDAO.save(indicatorNew);
|
95
|
|
96
|
List<String> indicators = section.getIndicators();
|
97
|
indicators.add(indicatorNew.getId());
|
98
|
|
99
|
sectionDAO.save(section);
|
100
|
}
|
101
|
}
|
102
|
|
103
|
public void onUpdateDefaultIndicator(Indicator indicator, Stakeholder stakeholder) throws UnsupportedEncodingException {
|
104
|
log.debug("On update default indicator");
|
105
|
|
106
|
// indicator already exists - check if changed and update all indicators based on it
|
107
|
|
108
|
boolean changed = false;
|
109
|
List<Indicator> indicators = indicatorDAO.findByDefaultId(indicator.getId());
|
110
|
|
111
|
for(Indicator indicatorBasedOnDefault : indicators) {
|
112
|
int i = 0;
|
113
|
List<IndicatorPath> indicatorPaths = indicatorBasedOnDefault.getIndicatorPaths();
|
114
|
|
115
|
for (IndicatorPath indicatorPath : indicator.getIndicatorPaths()) {
|
116
|
IndicatorPath indicatorPathBasedOnDefault = indicatorBasedOnDefault.getIndicatorPaths().get(i);
|
117
|
|
118
|
if(indicatorPathBasedOnDefault == null) {
|
119
|
// Add new indicator path in existing indicators
|
120
|
IndicatorPath indicatorPathNew = new IndicatorPath(indicatorPath);
|
121
|
parameterMapping(indicatorPathNew, stakeholder);
|
122
|
indicatorPaths.add(indicatorPathNew);
|
123
|
changed = true;
|
124
|
} else {
|
125
|
// Check if there are changes in indicator path and update existing indicators if needed
|
126
|
if(!indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())) {
|
127
|
indicatorPathBasedOnDefault.setType(indicatorPath.getType());
|
128
|
changed = true;
|
129
|
}
|
130
|
if(!indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())) {
|
131
|
indicatorPathBasedOnDefault.setSource(indicatorPath.getSource());
|
132
|
changed = true;
|
133
|
}
|
134
|
if(!indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())) {
|
135
|
indicatorPathBasedOnDefault.setUrl(indicatorPath.getUrl());
|
136
|
changed = true;
|
137
|
}
|
138
|
if(!indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject())) {
|
139
|
indicatorPathBasedOnDefault.setChartObject(indicatorPath.getChartObject());
|
140
|
changed = true;
|
141
|
}
|
142
|
if(indicatorPath.getParameters().size() != indicatorPathBasedOnDefault.getParameters().size()) {
|
143
|
for (Map.Entry<String, String> parameter : indicatorPath.getParameters().entrySet()) {
|
144
|
if(!indicatorPathBasedOnDefault.getParameters().containsKey(parameter.getKey())) {
|
145
|
indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
|
146
|
}
|
147
|
}
|
148
|
parameterMapping(indicatorPathBasedOnDefault, stakeholder);
|
149
|
changed = true;
|
150
|
}
|
151
|
int j=0;
|
152
|
for(String jsonString : indicatorPath.getJsonPath()) {
|
153
|
String jsonStringBasedOnDefault = indicatorPathBasedOnDefault.getJsonPath().get(j);
|
154
|
if(!jsonString.equals(jsonStringBasedOnDefault)) {
|
155
|
indicatorPathBasedOnDefault.getJsonPath().set(j, jsonString);
|
156
|
changed = true;
|
157
|
}
|
158
|
j++;
|
159
|
}
|
160
|
}
|
161
|
i++;
|
162
|
}
|
163
|
if(!changed) {
|
164
|
break;
|
165
|
}
|
166
|
indicatorDAO.save(indicatorBasedOnDefault);
|
167
|
}
|
168
|
}
|
169
|
|
170
|
public void parameterMapping(IndicatorPath indicatorPath, Stakeholder stakeholder) throws UnsupportedEncodingException {
|
171
|
if (indicatorPath.getParameters().containsKey("index_name")) {
|
172
|
indicatorPath.getParameters().put("index_name", stakeholder.getIndex_name());
|
173
|
} else if (indicatorPath.getParameters().containsKey("index_shortName")) {
|
174
|
indicatorPath.getParameters().put("index_shortName", stakeholder.getIndex_name().toLowerCase());
|
175
|
} else if (indicatorPath.getParameters().containsKey("index_id")) {
|
176
|
indicatorPath.getParameters().put("index_id", stakeholder.getIndex_id());
|
177
|
}
|
178
|
|
179
|
|
180
|
String url = indicatorPath.getUrl();
|
181
|
String encoded_index_id = urlEncode(URLEncoder.encode(stakeholder.getIndex_id(), "UTF-8"));
|
182
|
url = url.replace("index_id", encoded_index_id);
|
183
|
String encoded_index_name = urlEncode(URLEncoder.encode(stakeholder.getIndex_name(), "UTF-8"));
|
184
|
url = url.replace("index_name", encoded_index_name);
|
185
|
String encoded_index_shortName = urlEncode(URLEncoder.encode(stakeholder.getIndex_shortName(), "UTF-8"));
|
186
|
url = url.replace("index_shortName", encoded_index_shortName);
|
187
|
indicatorPath.setUrl(url);
|
188
|
}
|
189
|
|
190
|
public String urlEncode(String encodedIndicatorPathField) {
|
191
|
String indicatorPathField = "";
|
192
|
|
193
|
for( int i=0; i<encodedIndicatorPathField.length(); i++ ){
|
194
|
String character = encodedIndicatorPathField.substring(i, i+1);
|
195
|
|
196
|
if(character.equals("+")) {
|
197
|
indicatorPathField = indicatorPathField.concat("%20");
|
198
|
} else if(character.equals("%")) {
|
199
|
//grab the hex in pairs
|
200
|
String output = encodedIndicatorPathField.substring(i+1, (i + 3));
|
201
|
|
202
|
if(output.equals("7E") || output.equals("27") || output.equals("28") || output.equals("29") || output.equals("21")) {
|
203
|
//convert hex to decimal
|
204
|
int decimal = Integer.parseInt(output, 16);
|
205
|
//convert the decimal to character
|
206
|
StringBuilder sb = new StringBuilder();
|
207
|
sb.append((char) decimal);
|
208
|
|
209
|
indicatorPathField = indicatorPathField.concat(sb.toString());
|
210
|
} else {
|
211
|
indicatorPathField = indicatorPathField.concat(character + output);
|
212
|
}
|
213
|
|
214
|
i += 2;
|
215
|
} else {
|
216
|
indicatorPathField = indicatorPathField.concat(character);
|
217
|
}
|
218
|
}
|
219
|
|
220
|
return indicatorPathField;
|
221
|
}
|
222
|
|
223
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/delete", method = RequestMethod.DELETE)
|
224
|
public boolean deleteIndicator(@PathVariable("stakeholderId") String stakeholderId,
|
225
|
@PathVariable("topicId") String topicId,
|
226
|
@PathVariable("categoryId") String categoryId,
|
227
|
@PathVariable("subcategoryId") String subcategoryId,
|
228
|
@PathVariable("sectionId") String sectionId,
|
229
|
@PathVariable("indicatorId") String indicatorId) {
|
230
|
log.debug("delete indicator");
|
231
|
log.debug("Id: "+indicatorId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
|
232
|
|
233
|
Indicator indicator = indicatorDAO.findById(indicatorId);
|
234
|
if(indicator != null) {
|
235
|
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
|
236
|
|
237
|
List<String> indicators = section.getIndicators();
|
238
|
|
239
|
int index = indicators.indexOf(indicatorId);
|
240
|
if (index != -1) {
|
241
|
indicators.remove(index);
|
242
|
sectionDAO.save(section);
|
243
|
|
244
|
indicatorDAO.delete(indicatorId);
|
245
|
log.debug("Indicator deleted!");
|
246
|
} else {
|
247
|
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); -> Section: section.getTitle();
|
248
|
throw new PathNotValidException("Delete indicator: Indicator with id: "+indicatorId+" not found in Sectiom: "+sectionId);
|
249
|
}
|
250
|
} else {
|
251
|
// EXCEPTION - Indicator not found
|
252
|
throw new EntityNotFoundException("Delete indicator: Indicator with id: "+indicatorId+" not found");
|
253
|
}
|
254
|
return true;
|
255
|
}
|
256
|
|
257
|
// @RequestMapping(value = "/{stakeholderId}/charts/delete", method = RequestMethod.DELETE)
|
258
|
// public boolean deleteAllChartIndicators(@PathVariable("stakeholderId") String stakeholderId) {
|
259
|
// log.debug("delete all chart indicators of stakeholder");
|
260
|
// log.debug("Stakeholder: "+stakeholderId);
|
261
|
//
|
262
|
// Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
|
263
|
// if(stakeholder != null) {
|
264
|
//
|
265
|
// for(String topicId : stakeholder.getTopics()) {
|
266
|
// Topic<String> topic = topicDAO.findById(topicId);
|
267
|
// if(topic != null) {
|
268
|
// for(String categoryId : topic.getCategories()) {
|
269
|
// Category<String> category = categoryDAO.findById(categoryId);
|
270
|
// if(category != null) {
|
271
|
// for(String subcategoryId : category.getSubCategories()) {
|
272
|
// SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
|
273
|
// if(subcategory != null) {
|
274
|
//
|
275
|
// for(String sectionId : subcategory.getCharts()) {
|
276
|
// Section<String> section = sectionDAO.findById(sectionId);
|
277
|
// if (section != null) {
|
278
|
//
|
279
|
// List<String> indicators = section.getIndicators();
|
280
|
// Iterator<String> indicatorsIterator = section.getIndicators().iterator();
|
281
|
//
|
282
|
// while (indicatorsIterator.hasNext()) {
|
283
|
// String indicatorId = indicatorsIterator.next();
|
284
|
// Indicator indicator = indicatorDAO.findById(indicatorId);
|
285
|
// if (indicator != null) {
|
286
|
// int index = indicators.indexOf(indicatorId);
|
287
|
// if (index != -1) {
|
288
|
// indicatorsIterator.remove();
|
289
|
// //indicators.remove(index);
|
290
|
//
|
291
|
// indicatorDAO.delete(indicatorId);
|
292
|
// log.debug("Indicator deleted!");
|
293
|
// } else {
|
294
|
// // EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); -> Section: section.getTitle();
|
295
|
// throw new PathNotValidException("Delete indicator: Indicator with id: " + indicatorId + " not found in Section: " + sectionId);
|
296
|
// }
|
297
|
// } else {
|
298
|
// // EXCEPTION - Indicator not found
|
299
|
// throw new EntityNotFoundException("Delete indicator: Indicator with id: " + indicatorId + " not found");
|
300
|
// }
|
301
|
// }
|
302
|
// sectionDAO.save(section);
|
303
|
// } else {
|
304
|
// // EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias();
|
305
|
// throw new PathNotValidException("Delete indicator: Section with id: " + sectionId + " not found in SubCategory: " + subcategoryId);
|
306
|
// }
|
307
|
// }
|
308
|
// } else {
|
309
|
// // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
|
310
|
// throw new PathNotValidException("Delete indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
|
311
|
// }
|
312
|
// }
|
313
|
// } else {
|
314
|
// // EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
|
315
|
// throw new PathNotValidException("Delete indicator: Category with id: "+categoryId+" not found in Topic: "+topicId);
|
316
|
// }
|
317
|
// }
|
318
|
// } else {
|
319
|
// // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
|
320
|
// throw new PathNotValidException("Delete indicator: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
|
321
|
// }
|
322
|
// }
|
323
|
// } else {
|
324
|
// // EXCEPTION - Stakeholder not found
|
325
|
// throw new EntityNotFoundException("Delete indicator: Stakeholder with id: "+stakeholderId+" not found");
|
326
|
// }
|
327
|
// return true;
|
328
|
// }
|
329
|
|
330
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{type}/reorder", method = RequestMethod.POST)
|
331
|
public List<Indicator> reorderIndicators(@PathVariable("stakeholderId") String stakeholderId,
|
332
|
@PathVariable("topicId") String topicId,
|
333
|
@PathVariable("categoryId") String categoryId,
|
334
|
@PathVariable("subcategoryId") String subcategoryId,
|
335
|
@PathVariable("sectionId") String sectionId,
|
336
|
@PathVariable("type") String type,
|
337
|
@RequestBody List<String> indicators) {
|
338
|
log.debug("reorder indicators of type: "+type);
|
339
|
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
|
340
|
|
341
|
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, type);
|
342
|
|
343
|
section.setIndicators(indicators);
|
344
|
|
345
|
sectionDAO.save(section);
|
346
|
log.debug("Indicators reordered!");
|
347
|
|
348
|
List<Indicator> indicatorsFull = new ArrayList<>();
|
349
|
for(String indicatorId : indicators) {
|
350
|
indicatorsFull.add(indicatorDAO.findById(indicatorId));
|
351
|
}
|
352
|
return indicatorsFull;
|
353
|
}
|
354
|
|
355
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/toggle-status", method = RequestMethod.POST)
|
356
|
public Boolean toggleIndicatorStatus(@PathVariable("stakeholderId") String stakeholderId,
|
357
|
@PathVariable("topicId") String topicId,
|
358
|
@PathVariable("categoryId") String categoryId,
|
359
|
@PathVariable("subcategoryId") String subcategoryId,
|
360
|
@PathVariable("sectionId") String sectionId,
|
361
|
@PathVariable("indicatorId") String indicatorId) {
|
362
|
log.debug("toggle indicator status (isActive)");
|
363
|
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId+ " - Indicator: "+indicatorId);
|
364
|
|
365
|
Indicator indicator = indicatorDAO.findById(indicatorId);
|
366
|
if (indicator == null) {
|
367
|
// EXCEPTION - Indicator not found
|
368
|
throw new EntityNotFoundException("Toggle indicator status: Indicator with id: "+indicatorId+" not found");
|
369
|
}
|
370
|
indicator.setIsActive(!indicator.getIsActive());
|
371
|
|
372
|
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator);
|
373
|
|
374
|
return indicator.getIsActive();
|
375
|
}
|
376
|
|
377
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/toggle-access", method = RequestMethod.POST)
|
378
|
public Boolean toggleIndicatorAccess(@PathVariable("stakeholderId") String stakeholderId,
|
379
|
@PathVariable("topicId") String topicId,
|
380
|
@PathVariable("categoryId") String categoryId,
|
381
|
@PathVariable("subcategoryId") String subcategoryId,
|
382
|
@PathVariable("sectionId") String sectionId,
|
383
|
@PathVariable("indicatorId") String indicatorId) {
|
384
|
log.debug("toggle indicator access (isPublic)");
|
385
|
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId+ " - Indicator: "+indicatorId);
|
386
|
|
387
|
Indicator indicator = indicatorDAO.findById(indicatorId);
|
388
|
if (indicator == null) {
|
389
|
// EXCEPTION - Indicator not found
|
390
|
throw new EntityNotFoundException("Toggle indicator access: Indicator with id: "+indicatorId+" not found");
|
391
|
}
|
392
|
indicator.setIsPublic(!indicator.getIsPublic());
|
393
|
|
394
|
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator);
|
395
|
|
396
|
return indicator.getIsPublic();
|
397
|
}
|
398
|
|
399
|
public void toggleIndicator(String stakeholderId, String topicId, String categoryId, String subcategoryId, String sectionId, Indicator indicator) {
|
400
|
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
|
401
|
List<String> indicators = section.getIndicators();
|
402
|
|
403
|
if(indicators.contains(indicator.getId())) {
|
404
|
indicatorDAO.save(indicator);
|
405
|
log.debug("Indicator toggled!");
|
406
|
} else {
|
407
|
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias(); -> Section: section.getTitle();
|
408
|
throw new PathNotValidException("Toggle indicators: Indicator with id: "+indicator.getId()+" not found in Section: "+sectionId);
|
409
|
}
|
410
|
|
411
|
}
|
412
|
|
413
|
private Section checkForExceptions(String stakeholderId, String topicId, String categoryId, String subcategoryId, String sectionId, String indicatorType) {
|
414
|
|
415
|
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
|
416
|
|
417
|
if(stakeholder == null) {
|
418
|
// EXCEPTION - Stakeholder not found
|
419
|
throw new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " not found");
|
420
|
}
|
421
|
|
422
|
Topic<String> topic = topicDAO.findById(topicId);
|
423
|
if(topic == null) {
|
424
|
// EXCEPTION - Topic not found
|
425
|
throw new EntityNotFoundException("Save indicator: Topic with id: "+topicId+" not found");
|
426
|
}
|
427
|
|
428
|
if(!stakeholder.getTopics().contains(topicId)) {
|
429
|
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
|
430
|
throw new PathNotValidException("Save indicator: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId);
|
431
|
}
|
432
|
|
433
|
Category<String> category = categoryDAO.findById(categoryId);
|
434
|
if(category == null) {
|
435
|
// EXCEPTION - Category not found
|
436
|
throw new EntityNotFoundException("Save indicator: Category with id: "+categoryId+" not found");
|
437
|
}
|
438
|
|
439
|
if(!topic.getCategories().contains(categoryId)) {
|
440
|
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
|
441
|
throw new PathNotValidException("Save indicator: Category with id: "+categoryId+" not found in Topic: "+topicId);
|
442
|
}
|
443
|
|
444
|
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
|
445
|
if(subcategory == null) {
|
446
|
// EXCEPTION - SubCategory not found
|
447
|
throw new EntityNotFoundException("Save indicator: SubCategory with id: "+subcategoryId+" not found");
|
448
|
}
|
449
|
|
450
|
if (!category.getSubCategories().contains(subcategoryId)) {
|
451
|
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
|
452
|
throw new PathNotValidException("Save indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
|
453
|
}
|
454
|
|
455
|
Section<String> section = sectionDAO.findById(sectionId);
|
456
|
if(section == null) {
|
457
|
// EXCEPTION - Section not found
|
458
|
throw new EntityNotFoundException("Save indicator: Section with id: "+sectionId+" not found");
|
459
|
}
|
460
|
|
461
|
if(indicatorType.equals("chart")) {
|
462
|
if (!subcategory.getCharts().contains(sectionId)) {
|
463
|
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias();
|
464
|
throw new PathNotValidException("Save indicator: SubCategory with id: " + subcategoryId + " not found in Category: " + categoryId);
|
465
|
}
|
466
|
} else if(indicatorType.equals("number")) {
|
467
|
if (!subcategory.getNumbers().contains(sectionId)) {
|
468
|
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias();
|
469
|
throw new PathNotValidException("Save indicator: SubCategory with id: " + subcategoryId + " not found in Category: " + categoryId);
|
470
|
}
|
471
|
}
|
472
|
|
473
|
return section;
|
474
|
}
|
475
|
}
|