2019-11-22 16:50:59 +01:00
|
|
|
package eu.dnetlib.uoamonitorservice.controllers;
|
|
|
|
|
|
|
|
|
|
|
|
import eu.dnetlib.uoamonitorservice.entities.*;
|
2024-03-08 19:55:51 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
2024-03-14 18:01:28 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.service.*;
|
2022-10-10 14:27:17 +02:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2019-11-22 16:50:59 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2020-11-11 13:45:59 +01:00
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
2019-11-22 16:50:59 +01:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin(origins = "*")
|
|
|
|
public class IndicatorController {
|
2022-10-10 14:27:17 +02:00
|
|
|
private final Logger log = LogManager.getLogger(this.getClass());
|
2019-11-22 16:50:59 +01:00
|
|
|
|
2024-03-14 18:01:28 +01:00
|
|
|
private final StakeholderService stakeholderService;
|
|
|
|
private final TopicService topicService;
|
|
|
|
private final CategoryService categoryService;
|
|
|
|
private final SubCategoryService subCategoryService;
|
|
|
|
private final SectionService sectionService;
|
|
|
|
private final IndicatorService indicatorService;
|
2021-07-21 11:46:49 +02:00
|
|
|
|
|
|
|
@Autowired
|
2024-03-14 18:01:28 +01:00
|
|
|
public IndicatorController(StakeholderService stakeholderService, TopicService topicService, CategoryService categoryService,
|
|
|
|
SubCategoryService subCategoryService, SectionService sectionService, IndicatorService indicatorService) {
|
|
|
|
this.stakeholderService = stakeholderService;
|
|
|
|
this.topicService = topicService;
|
|
|
|
this.categoryService = categoryService;
|
|
|
|
this.subCategoryService = subCategoryService;
|
|
|
|
this.sectionService = sectionService;
|
|
|
|
this.indicatorService = indicatorService;
|
|
|
|
}
|
2021-07-21 11:46:49 +02:00
|
|
|
|
2024-03-14 18:01:28 +01:00
|
|
|
/*@PreAuthorize("isAuthenticated()")
|
2021-07-21 11:46:49 +02:00
|
|
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save-bulk", method = RequestMethod.POST)
|
|
|
|
public Stakeholder saveBulkIndicators(@PathVariable("stakeholderId") String stakeholderId,
|
2024-03-06 00:48:31 +01:00
|
|
|
@PathVariable("topicId") String topicId,
|
|
|
|
@PathVariable("categoryId") String categoryId,
|
|
|
|
@PathVariable("subcategoryId") String subcategoryId,
|
|
|
|
@RequestBody List<Section<Indicator>> sections) throws UnsupportedEncodingException {
|
2021-07-21 11:46:49 +02:00
|
|
|
log.debug("save bulk indicators");
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId);
|
2021-07-21 11:46:49 +02:00
|
|
|
|
2024-03-08 19:55:51 +01:00
|
|
|
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
|
2021-07-21 11:46:49 +02:00
|
|
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
2022-09-08 22:34:25 +02:00
|
|
|
createSectionsAndSaveBulk(date, sections, stakeholder, topicId, categoryId, subcategoryId);
|
2023-07-04 15:02:34 +02:00
|
|
|
return stakeholderController.setFullEntities(stakeholder);
|
2021-07-21 11:46:49 +02:00
|
|
|
}
|
|
|
|
|
2022-09-08 22:34:25 +02:00
|
|
|
private void createSectionsAndSaveBulk(Date date, List<Section<Indicator>> old_sections,
|
2024-03-06 00:48:31 +01:00
|
|
|
Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) throws UnsupportedEncodingException {
|
|
|
|
for (Section<Indicator> section : old_sections) {
|
|
|
|
if (section == null) {
|
2023-07-10 17:00:27 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-09-08 22:34:25 +02:00
|
|
|
Section chart_section = null;
|
|
|
|
Section number_section = null;
|
|
|
|
|
|
|
|
List<String> chart_indicators = null;
|
|
|
|
List<String> number_indicators = null;
|
|
|
|
|
2024-03-06 00:48:31 +01:00
|
|
|
if (section.getType().equals("chart")) {
|
2024-01-24 16:39:37 +01:00
|
|
|
chart_section = createSection(chart_section, "chart", section.getTitle(), date, stakeholder, topicId, categoryId, subcategoryId);
|
2022-09-08 22:34:25 +02:00
|
|
|
chart_indicators = chart_section.getIndicators();
|
2024-03-06 00:48:31 +01:00
|
|
|
} else if (section.getType().equals("number")) {
|
2024-01-24 16:39:37 +01:00
|
|
|
number_section = createSection(number_section, "number", section.getTitle(), date, stakeholder, topicId, categoryId, subcategoryId);
|
2022-09-08 22:34:25 +02:00
|
|
|
number_indicators = number_section.getIndicators();
|
|
|
|
}
|
2021-07-21 11:46:49 +02:00
|
|
|
|
2022-09-08 22:34:25 +02:00
|
|
|
List<Indicator> indicators = section.getIndicators();
|
|
|
|
for (Indicator indicator : indicators) {
|
2024-03-06 00:48:31 +01:00
|
|
|
if (indicator == null) {
|
2023-07-10 17:00:27 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-09-08 22:34:25 +02:00
|
|
|
if (indicator.getType().equals("chart")) {
|
2023-07-03 09:42:46 +02:00
|
|
|
saveIndicatorAndAddInSection(indicator, date, stakeholder, subcategoryId, chart_section, chart_indicators);
|
2021-07-21 11:46:49 +02:00
|
|
|
|
2022-09-08 22:34:25 +02:00
|
|
|
} else if (indicator.getType().equals("number")) {
|
2023-07-03 09:42:46 +02:00
|
|
|
saveIndicatorAndAddInSection(indicator, date, stakeholder, subcategoryId, number_section, number_indicators);
|
2021-07-21 11:46:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-08 22:34:25 +02:00
|
|
|
if (chart_section != null) {
|
|
|
|
sectionDAO.save(chart_section);
|
|
|
|
}
|
|
|
|
if (number_section != null) {
|
|
|
|
sectionDAO.save(number_section);
|
|
|
|
}
|
2021-07-21 11:46:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Section createSection(Section section, String type, String title, Date date,
|
|
|
|
Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) {
|
|
|
|
section = new Section<>();
|
|
|
|
section.setType(type);
|
|
|
|
section.setTitle(title);
|
|
|
|
section.setStakeholderAlias(stakeholder.getAlias());
|
|
|
|
section.setUpdateDate(date);
|
|
|
|
section.setCreationDate(date);
|
|
|
|
section.setIndicators(new ArrayList<>());
|
2022-09-08 22:34:25 +02:00
|
|
|
section = sectionController.saveSection(stakeholder.getId(), topicId, categoryId, subcategoryId, "-1", section);
|
2021-07-21 11:46:49 +02:00
|
|
|
|
|
|
|
return section;
|
|
|
|
}
|
|
|
|
|
2023-07-03 09:42:46 +02:00
|
|
|
private void saveIndicatorAndAddInSection(Indicator indicator, Date date, Stakeholder stakeholder, String subcategoryId, Section section, List<String> indicators) throws UnsupportedEncodingException {
|
2021-07-21 11:46:49 +02:00
|
|
|
// indicator does not exist in DB
|
|
|
|
indicator.setCreationDate(date);
|
|
|
|
indicator.setUpdateDate(date);
|
|
|
|
|
|
|
|
if (stakeholder.getDefaultId() == null) { // this indicator belongs in default profile and it is new
|
|
|
|
indicatorDAO.save(indicator);
|
2023-07-03 09:42:46 +02:00
|
|
|
onSaveDefaultIndicator(indicator, section, subcategoryId);
|
2021-07-21 11:46:49 +02:00
|
|
|
} else { // this indicator belongs in a stakeholder's profile and it is new
|
|
|
|
indicatorDAO.save(indicator);
|
|
|
|
}
|
|
|
|
|
|
|
|
indicators.add(indicator.getId());
|
|
|
|
log.debug("Indicator saved!");
|
|
|
|
}
|
2024-03-14 18:01:28 +01:00
|
|
|
*/
|
|
|
|
/* @PreAuthorize("isAuthenticated()")
|
2020-01-10 11:48:24 +01:00
|
|
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/save", method = RequestMethod.POST)
|
2019-11-22 16:50:59 +01:00
|
|
|
public Indicator saveIndicator(@PathVariable("stakeholderId") String stakeholderId,
|
|
|
|
@PathVariable("topicId") String topicId,
|
|
|
|
@PathVariable("categoryId") String categoryId,
|
|
|
|
@PathVariable("subcategoryId") String subcategoryId,
|
2020-01-10 11:48:24 +01:00
|
|
|
@PathVariable("sectionId") String sectionId,
|
2020-01-17 12:43:31 +01:00
|
|
|
@RequestBody Indicator indicator) throws UnsupportedEncodingException {
|
2019-11-22 16:50:59 +01:00
|
|
|
log.debug("save indicator");
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("Name: " + indicator.getName() + " - Id: " + indicator.getId() + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId);
|
2019-11-22 16:50:59 +01:00
|
|
|
|
2020-01-10 11:48:24 +01:00
|
|
|
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
|
2019-11-22 16:50:59 +01:00
|
|
|
|
2020-11-11 13:45:59 +01:00
|
|
|
Date date = new Date();
|
|
|
|
indicator.setUpdateDate(date);
|
|
|
|
|
2020-05-18 11:17:05 +02:00
|
|
|
Indicator oldIndicator = null;
|
2024-03-06 00:48:31 +01:00
|
|
|
if (indicator.getId() != null) {
|
2020-05-18 11:17:05 +02:00
|
|
|
oldIndicator = indicatorDAO.findById(indicator.getId());
|
2024-03-06 00:48:31 +01:00
|
|
|
if (oldIndicator == null) {
|
[Trunk | Monitor Service]:
1. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java && SectionController.java && IndicatorController.java:
a. Comment logs for get requests.
b. Use "ForbiddenException" instead of "AccessDeniedException"
c. On /save, if full entity has id (already in DB), if not found in DB throw EntityNotFoundException.
d. Get children (e.g. when saving a Topic, get its categories) from DB.
2. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java:
In /reorder, if there are in DB, ids that are missing from reordered list, do reordering and add in the end of list the missing ids.
3. ReorderEvent.java: [NEW] Added class ReorderEvent with fields "action" (String), "target" (String), "ids" (List<String>) (used in IndicatorController.java).
4. IndicatorController.java:
a. In /reorder, @RequestBody changed from List<String> indicators to ReorderEvent reorderEvent.
b. If there are in DB, ids that are missing from reordered list AND missing id is not moved to other section (action = removed and target = missing id), do reordering and add in the end of list the missing ids.
5. ExceptionsHandler.java: exception handler methods "invalidInput()", "nullPointerException()", "notFoundException()" moved to "Admin Tools Library" - "accessDeniedException()" is removed.
6. responses/ExceptionResponse.java: File and folder deleted (moved to "Admin Tools Library").
7. RolesUtils.java: Added method "isLoggedIn()" (checks if no roles for user, or user has role "ROLE_ANONYMOUS").
2020-12-09 15:24:27 +01:00
|
|
|
// EXCEPTION - Indicator not found
|
|
|
|
throw new EntityNotFoundException("save indicator: Indicator with id: " + indicator.getId() + " not found");
|
|
|
|
}
|
2020-11-11 13:45:59 +01:00
|
|
|
} else { // indicator does not exist in DB
|
|
|
|
indicator.setCreationDate(date);
|
2020-05-18 11:17:05 +02:00
|
|
|
}
|
|
|
|
|
2020-01-10 11:48:24 +01:00
|
|
|
String indicatorId = indicator.getId();
|
2019-11-22 16:50:59 +01:00
|
|
|
|
2024-03-08 19:55:51 +01:00
|
|
|
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
|
2020-01-10 11:48:24 +01:00
|
|
|
// this indicator belongs in default profile and it is new or it is updated
|
2024-03-06 00:48:31 +01:00
|
|
|
if (stakeholder.getDefaultId() == null) {
|
|
|
|
if (indicatorId == null) {
|
2020-11-11 13:45:59 +01:00
|
|
|
indicatorDAO.save(indicator);
|
2023-07-03 09:42:46 +02:00
|
|
|
onSaveDefaultIndicator(indicator, section, subcategoryId);
|
2024-03-06 00:48:31 +01:00
|
|
|
} else {
|
2020-05-18 11:17:05 +02:00
|
|
|
onUpdateDefaultIndicator(indicator, stakeholder, oldIndicator);
|
2020-11-11 13:45:59 +01:00
|
|
|
indicatorDAO.save(indicator);
|
2020-01-10 11:48:24 +01:00
|
|
|
}
|
2020-11-11 13:45:59 +01:00
|
|
|
} else {
|
|
|
|
indicatorDAO.save(indicator);
|
2020-01-10 11:48:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
List<String> indicators = section.getIndicators();
|
|
|
|
|
|
|
|
int index = indicators.indexOf(indicator.getId());
|
|
|
|
if (index == -1) {
|
|
|
|
indicators.add(indicator.getId());
|
|
|
|
sectionDAO.save(section);
|
|
|
|
log.debug("Indicator saved!");
|
2019-11-22 16:50:59 +01:00
|
|
|
}
|
2020-01-10 11:48:24 +01:00
|
|
|
|
2019-11-22 16:50:59 +01:00
|
|
|
return indicator;
|
|
|
|
}
|
|
|
|
|
2023-07-03 09:42:46 +02:00
|
|
|
public void onSaveDefaultIndicator(Indicator indicator, Section defaultSection, String defaultSubcategoryId) throws UnsupportedEncodingException {
|
2019-12-19 16:04:25 +01:00
|
|
|
log.debug("On save default indicator");
|
|
|
|
|
|
|
|
// new indicator in default profile - add it on profiles of the same type
|
2023-07-03 09:42:46 +02:00
|
|
|
List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubcategoryId);
|
|
|
|
for (SubCategory subCategory : subCategories) {
|
|
|
|
|
|
|
|
List<String> sections = null;
|
2024-03-06 00:48:31 +01:00
|
|
|
if (defaultSection.getType().equals("chart")) {
|
2023-07-03 09:42:46 +02:00
|
|
|
sections = subCategory.getCharts();
|
|
|
|
} else {
|
|
|
|
sections = subCategory.getNumbers();
|
2019-12-19 16:04:25 +01:00
|
|
|
}
|
|
|
|
|
2023-07-03 09:42:46 +02:00
|
|
|
for (String sectionId : sections) {
|
|
|
|
Section section = sectionDAO.findById(sectionId);
|
2024-03-06 00:48:31 +01:00
|
|
|
if (section.getDefaultId() != null && section.getDefaultId().equals(defaultSection.getId())) {
|
2023-07-03 09:42:46 +02:00
|
|
|
Indicator indicatorNew = new Indicator();
|
|
|
|
indicatorNew.copyFromDefault(indicator, subCategory.getVisibility());
|
|
|
|
indicatorDAO.save(indicatorNew);
|
|
|
|
List<String> indicators = section.getIndicators();
|
|
|
|
indicators.add(indicatorNew.getId());
|
|
|
|
sectionDAO.save(section);
|
|
|
|
}
|
|
|
|
}
|
2019-12-19 16:04:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 11:17:05 +02:00
|
|
|
public void onUpdateDefaultIndicator(Indicator indicator, Stakeholder stakeholder, Indicator oldIndicator) throws UnsupportedEncodingException {
|
2019-12-19 16:04:25 +01:00
|
|
|
log.debug("On update default indicator");
|
|
|
|
|
|
|
|
// indicator already exists - check if changed and update all indicators based on it
|
|
|
|
|
2020-11-11 13:45:59 +01:00
|
|
|
boolean changed;
|
2019-12-19 16:04:25 +01:00
|
|
|
List<Indicator> indicators = indicatorDAO.findByDefaultId(indicator.getId());
|
|
|
|
|
2024-03-06 00:48:31 +01:00
|
|
|
for (Indicator indicatorBasedOnDefault : indicators) {
|
2020-11-11 13:45:59 +01:00
|
|
|
changed = false;
|
2024-03-06 00:48:31 +01:00
|
|
|
if ((
|
2020-12-22 10:29:17 +01:00
|
|
|
(indicator.getName() == null && oldIndicator.getName() != null)
|
|
|
|
||
|
|
|
|
(indicator.getName() != null && !indicator.getName().equals(indicatorBasedOnDefault.getName()))
|
|
|
|
) && (
|
|
|
|
(oldIndicator.getName() == null && indicatorBasedOnDefault.getName() == null)
|
|
|
|
||
|
|
|
|
(oldIndicator.getName() != null && oldIndicator.getName().equals(indicatorBasedOnDefault.getName()))
|
|
|
|
)) {
|
2020-05-18 11:17:05 +02:00
|
|
|
indicatorBasedOnDefault.setName(indicator.getName());
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
2024-03-06 00:48:31 +01:00
|
|
|
if (indicator.getDescription() != null && !indicator.getDescription().equals(indicatorBasedOnDefault.getDescription())
|
|
|
|
|| indicator.getDescription() == null && indicatorBasedOnDefault.getDescription() != null) {
|
2020-05-18 11:17:05 +02:00
|
|
|
|
2020-06-25 11:55:46 +02:00
|
|
|
indicatorBasedOnDefault.setDescription(indicator.getDescription());
|
2020-05-18 11:17:05 +02:00
|
|
|
changed = true;
|
|
|
|
}
|
2024-03-06 00:48:31 +01:00
|
|
|
if ((
|
2020-12-22 10:29:17 +01:00
|
|
|
(indicator.getAdditionalDescription() == null && oldIndicator.getAdditionalDescription() != null)
|
|
|
|
||
|
|
|
|
(indicator.getAdditionalDescription() != null && !indicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription()))
|
|
|
|
) && (
|
|
|
|
(oldIndicator.getAdditionalDescription() == null && indicatorBasedOnDefault.getAdditionalDescription() == null)
|
|
|
|
||
|
|
|
|
(oldIndicator.getAdditionalDescription() != null && oldIndicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription()))
|
|
|
|
)) {
|
2020-11-11 13:45:59 +01:00
|
|
|
indicatorBasedOnDefault.setAdditionalDescription(indicator.getAdditionalDescription());
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
2019-12-19 16:04:25 +01:00
|
|
|
int i = 0;
|
|
|
|
List<IndicatorPath> indicatorPaths = indicatorBasedOnDefault.getIndicatorPaths();
|
2024-03-06 00:48:31 +01:00
|
|
|
if (indicatorPaths == null && indicator.getIndicatorPaths() != null) {
|
2020-11-11 13:45:59 +01:00
|
|
|
indicatorPaths = new ArrayList<>();
|
|
|
|
}
|
2019-12-19 16:04:25 +01:00
|
|
|
|
|
|
|
for (IndicatorPath indicatorPath : indicator.getIndicatorPaths()) {
|
2020-11-11 13:45:59 +01:00
|
|
|
IndicatorPath indicatorPathBasedOnDefault = null;
|
2024-03-06 00:48:31 +01:00
|
|
|
if (i < indicatorPaths.size()) {
|
2020-11-11 13:45:59 +01:00
|
|
|
indicatorPathBasedOnDefault = indicatorPaths.get(i);
|
|
|
|
}
|
2019-12-19 16:04:25 +01:00
|
|
|
|
2024-03-06 00:48:31 +01:00
|
|
|
if (indicatorPathBasedOnDefault == null) {
|
2019-12-19 16:04:25 +01:00
|
|
|
// Add new indicator path in existing indicators
|
|
|
|
IndicatorPath indicatorPathNew = new IndicatorPath(indicatorPath);
|
|
|
|
indicatorPaths.add(indicatorPathNew);
|
|
|
|
changed = true;
|
|
|
|
} else {
|
2020-05-18 11:17:05 +02:00
|
|
|
IndicatorPath oldIndicatorPath = oldIndicator.getIndicatorPaths().get(i);
|
|
|
|
|
2019-12-19 16:04:25 +01:00
|
|
|
// Check if there are changes in indicator path and update existing indicators if needed
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("update indicator path: " + i + " (indicator id: " + indicatorBasedOnDefault.getId() + ")");
|
|
|
|
if ((
|
2020-12-22 10:29:17 +01:00
|
|
|
(indicatorPath.getType() == null && oldIndicatorPath.getType() != null)
|
|
|
|
||
|
|
|
|
(indicatorPath.getType() != null && !indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()))
|
|
|
|
) && (
|
|
|
|
(oldIndicatorPath.getType() == null && indicatorPathBasedOnDefault.getType() == null)
|
|
|
|
||
|
|
|
|
(oldIndicatorPath.getType() != null && oldIndicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()))
|
|
|
|
)) {
|
2019-12-19 16:04:25 +01:00
|
|
|
indicatorPathBasedOnDefault.setType(indicatorPath.getType());
|
2020-05-18 11:17:05 +02:00
|
|
|
changed = true; // parameter "type" needs to be changed as well
|
2019-12-19 16:04:25 +01:00
|
|
|
}
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("After type check: " + changed);
|
2023-05-03 12:02:56 +02:00
|
|
|
|
2024-03-06 00:48:31 +01:00
|
|
|
if ((
|
2023-05-03 12:02:56 +02:00
|
|
|
(indicatorPath.getFormat() == null && oldIndicatorPath.getFormat() != null)
|
|
|
|
||
|
|
|
|
(indicatorPath.getFormat() != null && !indicatorPath.getFormat().equals(indicatorPathBasedOnDefault.getFormat()))
|
|
|
|
) && (
|
|
|
|
(oldIndicatorPath.getFormat() == null && indicatorPathBasedOnDefault.getFormat() == null)
|
|
|
|
||
|
|
|
|
(oldIndicatorPath.getFormat() != null && oldIndicatorPath.getFormat().equals(indicatorPathBasedOnDefault.getFormat()))
|
|
|
|
)) {
|
|
|
|
indicatorPathBasedOnDefault.setFormat(indicatorPath.getFormat());
|
|
|
|
changed = true;
|
|
|
|
}
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("After type check: " + changed);
|
|
|
|
if ((
|
2020-12-22 10:29:17 +01:00
|
|
|
(indicatorPath.getSource() == null && oldIndicatorPath.getSource() != null)
|
|
|
|
||
|
|
|
|
(indicatorPath.getSource() != null && !indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))
|
|
|
|
) && (
|
|
|
|
(oldIndicatorPath.getSource() == null && indicatorPathBasedOnDefault.getSource() == null)
|
|
|
|
||
|
|
|
|
(oldIndicatorPath.getSource() != null && oldIndicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))
|
|
|
|
)) {
|
2019-12-19 16:04:25 +01:00
|
|
|
indicatorPathBasedOnDefault.setSource(indicatorPath.getSource());
|
|
|
|
changed = true;
|
|
|
|
}
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("After source check: " + changed);
|
|
|
|
if ((
|
2020-12-22 10:29:17 +01:00
|
|
|
(indicatorPath.getUrl() == null && oldIndicatorPath.getUrl() != null)
|
|
|
|
||
|
|
|
|
(indicatorPath.getUrl() != null && !indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl()))
|
|
|
|
) && (
|
|
|
|
(oldIndicatorPath.getUrl() == null && indicatorPathBasedOnDefault.getUrl() == null)
|
|
|
|
||
|
|
|
|
(oldIndicatorPath.getUrl() != null && oldIndicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl()))
|
|
|
|
)) {
|
2019-12-19 16:04:25 +01:00
|
|
|
indicatorPathBasedOnDefault.setUrl(indicatorPath.getUrl());
|
|
|
|
changed = true;
|
|
|
|
}
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("After url check: " + changed);
|
2020-05-18 11:17:05 +02:00
|
|
|
|
2024-03-06 00:48:31 +01:00
|
|
|
if ((
|
2020-12-22 10:29:17 +01:00
|
|
|
(indicatorPath.getChartObject() == null && oldIndicatorPath.getChartObject() != null)
|
2024-03-06 00:48:31 +01:00
|
|
|
||
|
|
|
|
(indicatorPath.getChartObject() != null && !indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject()))
|
|
|
|
) && (
|
2020-12-22 10:29:17 +01:00
|
|
|
(oldIndicatorPath.getChartObject() == null && indicatorPathBasedOnDefault.getChartObject() == null)
|
2024-03-06 00:48:31 +01:00
|
|
|
||
|
|
|
|
(oldIndicatorPath.getChartObject() != null && oldIndicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject()))
|
2020-12-22 10:29:17 +01:00
|
|
|
)) {
|
2020-05-18 11:17:05 +02:00
|
|
|
|
2019-12-19 16:04:25 +01:00
|
|
|
indicatorPathBasedOnDefault.setChartObject(indicatorPath.getChartObject());
|
|
|
|
changed = true;
|
|
|
|
}
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("After chartObject check: " + changed);
|
2020-05-18 11:17:05 +02:00
|
|
|
|
2024-03-06 00:48:31 +01:00
|
|
|
if (indicatorPath.getParameters() != null) {
|
2020-05-18 11:17:05 +02:00
|
|
|
if (indicatorPathBasedOnDefault.getParameters() == null) {
|
|
|
|
indicatorPathBasedOnDefault.setParameters(new HashMap<>());
|
2019-12-19 16:04:25 +01:00
|
|
|
}
|
2021-04-22 12:05:43 +02:00
|
|
|
for (Map.Entry<String, String> parameter : indicatorPath.getParameters().entrySet()) {
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("\nindicatorPath: parameter.getKey(): " + parameter.getKey() + " - value: " + parameter.getValue()
|
|
|
|
+ "\nindicatorPathBasedOnDefault:parameters:key: " + indicatorPathBasedOnDefault.getParameters().get(parameter.getKey())
|
|
|
|
+ "\noldIndicatorPath:parameters:key: " + (oldIndicatorPath.getParameters() == null ? "null" : oldIndicatorPath.getParameters().get(parameter.getKey())));
|
2021-04-22 12:05:43 +02:00
|
|
|
if (!indicatorPathBasedOnDefault.getParameters().containsKey(parameter.getKey())
|
|
|
|
|| (oldIndicatorPath.getParameters() == null || oldIndicatorPath.getParameters().get(parameter.getKey()) == null
|
2024-03-06 00:48:31 +01:00
|
|
|
|| (oldIndicatorPath.getParameters().get(parameter.getKey()).equals(indicatorPathBasedOnDefault.getParameters().get(parameter.getKey()))
|
|
|
|
&& !parameter.getValue().equals(indicatorPathBasedOnDefault.getParameters().get(parameter.getKey()))))
|
2021-04-22 12:05:43 +02:00
|
|
|
) {
|
|
|
|
indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// When deleting indicator path parameters in a default profile, delete them also from all children profiles
|
2024-03-06 00:48:31 +01:00
|
|
|
if (oldIndicatorPath.getParameters() != null && indicatorPath.getParameters().size() < oldIndicatorPath.getParameters().size()) {
|
2021-04-22 12:05:43 +02:00
|
|
|
for (Map.Entry<String, String> parameter : oldIndicatorPath.getParameters().entrySet()) {
|
2024-03-06 00:48:31 +01:00
|
|
|
if (!indicatorPath.getParameters().containsKey(parameter.getKey())) {
|
2021-04-22 12:05:43 +02:00
|
|
|
indicatorPathBasedOnDefault.getParameters().remove(parameter.getKey());
|
2020-05-18 11:17:05 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-22 12:05:43 +02:00
|
|
|
}
|
2019-12-19 16:04:25 +01:00
|
|
|
}
|
2020-11-11 13:45:59 +01:00
|
|
|
log.debug("After parameters check: " + changed);
|
2020-05-18 11:17:05 +02:00
|
|
|
|
2024-03-06 00:48:31 +01:00
|
|
|
if (indicatorPath.getJsonPath() != null) {
|
2020-11-11 13:45:59 +01:00
|
|
|
boolean jsonPathChanged = false;
|
|
|
|
boolean breaked = false;
|
|
|
|
|
|
|
|
int oldJsonPathSize = 0;
|
2024-03-06 00:48:31 +01:00
|
|
|
if (oldIndicatorPath.getJsonPath() != null) {
|
2020-11-11 13:45:59 +01:00
|
|
|
oldJsonPathSize = oldIndicatorPath.getJsonPath().size();
|
|
|
|
}
|
|
|
|
int basedOnDefaultJsonPathSize = 0;
|
2024-03-06 00:48:31 +01:00
|
|
|
if (indicatorPathBasedOnDefault.getJsonPath() != null) {
|
2020-11-11 13:45:59 +01:00
|
|
|
basedOnDefaultJsonPathSize = indicatorPathBasedOnDefault.getJsonPath().size();
|
|
|
|
}
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("old: " + oldJsonPathSize + " - based on default: " + basedOnDefaultJsonPathSize + " - new: " + indicatorPath.getJsonPath().size());
|
|
|
|
if (oldJsonPathSize == basedOnDefaultJsonPathSize) {
|
|
|
|
if (indicatorPathBasedOnDefault.getJsonPath() == null && indicatorPath.getJsonPath().size() > 0) {
|
2020-05-18 11:17:05 +02:00
|
|
|
indicatorPathBasedOnDefault.setJsonPath(new ArrayList<>());
|
|
|
|
}
|
|
|
|
|
2020-11-11 13:45:59 +01:00
|
|
|
int basedOnDefaultIndex = 0;
|
|
|
|
int oldIndex = 0;
|
|
|
|
|
|
|
|
Iterator<String> jsonStringBasedOnDefaultIterator = indicatorPathBasedOnDefault.getJsonPath().iterator();
|
|
|
|
while (jsonStringBasedOnDefaultIterator.hasNext()) {
|
|
|
|
String jsonStringBasedOnDefault = jsonStringBasedOnDefaultIterator.next();
|
2024-03-06 00:48:31 +01:00
|
|
|
if (oldIndicatorPath.getJsonPath().get(oldIndex).equals(jsonStringBasedOnDefault)) {
|
|
|
|
if (basedOnDefaultIndex >= indicatorPath.getJsonPath().size()) { // string deleted
|
2020-11-11 13:45:59 +01:00
|
|
|
jsonStringBasedOnDefaultIterator.remove();
|
|
|
|
jsonPathChanged = true;
|
|
|
|
} else { // check if string changed
|
2024-03-06 00:48:31 +01:00
|
|
|
if (!indicatorPath.getJsonPath().get(basedOnDefaultIndex).equals(jsonStringBasedOnDefault)) {
|
2020-11-11 13:45:59 +01:00
|
|
|
indicatorPathBasedOnDefault.getJsonPath().set(basedOnDefaultIndex, indicatorPath.getJsonPath().get(basedOnDefaultIndex));
|
|
|
|
jsonPathChanged = true;
|
|
|
|
}
|
|
|
|
basedOnDefaultIndex++;
|
|
|
|
}
|
|
|
|
oldIndex++;
|
|
|
|
} else {
|
|
|
|
breaked = true;
|
|
|
|
jsonPathChanged = false;
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("not the same: " + oldIndex);
|
2020-11-11 13:45:59 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 00:48:31 +01:00
|
|
|
int index = 0;
|
|
|
|
if (!breaked && indicatorPath.getJsonPath().size() > indicatorPathBasedOnDefault.getJsonPath().size()) { // strings added
|
2020-11-11 13:45:59 +01:00
|
|
|
jsonPathChanged = true;
|
2024-03-06 00:48:31 +01:00
|
|
|
for (index = indicatorPathBasedOnDefault.getJsonPath().size(); index < indicatorPath.getJsonPath().size(); index++) {
|
2020-11-11 13:45:59 +01:00
|
|
|
indicatorPathBasedOnDefault.getJsonPath().add(indicatorPath.getJsonPath().get(index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 00:48:31 +01:00
|
|
|
if (jsonPathChanged) {
|
2020-05-18 11:17:05 +02:00
|
|
|
changed = true;
|
|
|
|
}
|
2019-12-19 16:04:25 +01:00
|
|
|
}
|
2021-04-22 12:05:43 +02:00
|
|
|
// TODO when deleting indicator path json path strings... --> is this done? (line 327)
|
2019-12-19 16:04:25 +01:00
|
|
|
}
|
2020-11-11 13:45:59 +01:00
|
|
|
log.debug("After jsonPath check: " + changed);
|
2019-12-19 16:04:25 +01:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2020-11-11 13:45:59 +01:00
|
|
|
// TODO when deleting indicator paths...
|
2020-05-18 11:17:05 +02:00
|
|
|
|
2024-03-06 00:48:31 +01:00
|
|
|
if (!changed) {
|
2020-05-18 11:17:05 +02:00
|
|
|
// break;
|
|
|
|
continue;
|
2019-12-19 16:04:25 +01:00
|
|
|
}
|
2020-05-18 11:17:05 +02:00
|
|
|
|
2020-11-11 13:45:59 +01:00
|
|
|
indicatorBasedOnDefault.setUpdateDate(indicator.getUpdateDate());
|
2019-12-19 16:04:25 +01:00
|
|
|
indicatorDAO.save(indicatorBasedOnDefault);
|
|
|
|
}
|
|
|
|
}
|
2024-03-14 18:01:28 +01:00
|
|
|
*/
|
2020-11-11 13:45:59 +01:00
|
|
|
@PreAuthorize("isAuthenticated()")
|
2020-01-10 11:48:24 +01:00
|
|
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/delete", method = RequestMethod.DELETE)
|
2019-11-22 16:50:59 +01:00
|
|
|
public boolean deleteIndicator(@PathVariable("stakeholderId") String stakeholderId,
|
|
|
|
@PathVariable("topicId") String topicId,
|
|
|
|
@PathVariable("categoryId") String categoryId,
|
|
|
|
@PathVariable("subcategoryId") String subcategoryId,
|
2020-01-10 11:48:24 +01:00
|
|
|
@PathVariable("sectionId") String sectionId,
|
2020-06-22 21:58:40 +02:00
|
|
|
@PathVariable("indicatorId") String indicatorId,
|
|
|
|
@RequestParam(required = false) String children) {
|
2019-11-22 16:50:59 +01:00
|
|
|
log.debug("delete indicator");
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("Id: " + indicatorId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId);
|
2024-03-14 18:01:28 +01:00
|
|
|
Stakeholder stakeholder = this.stakeholderService.findById(stakeholderId);
|
|
|
|
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
|
|
|
Category category = this.categoryService.findByPath(topic, categoryId);
|
|
|
|
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
|
|
|
Section section = this.sectionService.findByPath(subCategory, sectionId);
|
|
|
|
Indicator indicator = this.indicatorService.findByPath(section, indicatorId);
|
|
|
|
this.indicatorService.delete(stakeholder.getType(), indicator, true);
|
2019-11-22 16:50:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-22 21:58:40 +02:00
|
|
|
|
2024-03-14 18:01:28 +01:00
|
|
|
/*@PreAuthorize("isAuthenticated()")
|
2020-01-10 11:48:24 +01:00
|
|
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{type}/reorder", method = RequestMethod.POST)
|
2019-11-26 12:08:36 +01:00
|
|
|
public List<Indicator> reorderIndicators(@PathVariable("stakeholderId") String stakeholderId,
|
2020-01-10 11:48:24 +01:00
|
|
|
@PathVariable("topicId") String topicId,
|
|
|
|
@PathVariable("categoryId") String categoryId,
|
|
|
|
@PathVariable("subcategoryId") String subcategoryId,
|
|
|
|
@PathVariable("sectionId") String sectionId,
|
|
|
|
@PathVariable("type") String type,
|
[Trunk | Monitor Service]:
1. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java && SectionController.java && IndicatorController.java:
a. Comment logs for get requests.
b. Use "ForbiddenException" instead of "AccessDeniedException"
c. On /save, if full entity has id (already in DB), if not found in DB throw EntityNotFoundException.
d. Get children (e.g. when saving a Topic, get its categories) from DB.
2. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java:
In /reorder, if there are in DB, ids that are missing from reordered list, do reordering and add in the end of list the missing ids.
3. ReorderEvent.java: [NEW] Added class ReorderEvent with fields "action" (String), "target" (String), "ids" (List<String>) (used in IndicatorController.java).
4. IndicatorController.java:
a. In /reorder, @RequestBody changed from List<String> indicators to ReorderEvent reorderEvent.
b. If there are in DB, ids that are missing from reordered list AND missing id is not moved to other section (action = removed and target = missing id), do reordering and add in the end of list the missing ids.
5. ExceptionsHandler.java: exception handler methods "invalidInput()", "nullPointerException()", "notFoundException()" moved to "Admin Tools Library" - "accessDeniedException()" is removed.
6. responses/ExceptionResponse.java: File and folder deleted (moved to "Admin Tools Library").
7. RolesUtils.java: Added method "isLoggedIn()" (checks if no roles for user, or user has role "ROLE_ANONYMOUS").
2020-12-09 15:24:27 +01:00
|
|
|
@RequestBody ReorderEvent reorderEvent) {
|
2024-03-06 00:48:31 +01:00
|
|
|
log.debug("reorder indicators of type: " + type);
|
|
|
|
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId);
|
2019-11-22 16:50:59 +01:00
|
|
|
|
[Trunk | Monitor Service]:
1. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java && SectionController.java && IndicatorController.java:
a. Comment logs for get requests.
b. Use "ForbiddenException" instead of "AccessDeniedException"
c. On /save, if full entity has id (already in DB), if not found in DB throw EntityNotFoundException.
d. Get children (e.g. when saving a Topic, get its categories) from DB.
2. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java:
In /reorder, if there are in DB, ids that are missing from reordered list, do reordering and add in the end of list the missing ids.
3. ReorderEvent.java: [NEW] Added class ReorderEvent with fields "action" (String), "target" (String), "ids" (List<String>) (used in IndicatorController.java).
4. IndicatorController.java:
a. In /reorder, @RequestBody changed from List<String> indicators to ReorderEvent reorderEvent.
b. If there are in DB, ids that are missing from reordered list AND missing id is not moved to other section (action = removed and target = missing id), do reordering and add in the end of list the missing ids.
5. ExceptionsHandler.java: exception handler methods "invalidInput()", "nullPointerException()", "notFoundException()" moved to "Admin Tools Library" - "accessDeniedException()" is removed.
6. responses/ExceptionResponse.java: File and folder deleted (moved to "Admin Tools Library").
7. RolesUtils.java: Added method "isLoggedIn()" (checks if no roles for user, or user has role "ROLE_ANONYMOUS").
2020-12-09 15:24:27 +01:00
|
|
|
List<String> indicators = reorderEvent.getIds();
|
|
|
|
String actionType = reorderEvent.getAction();
|
|
|
|
String targetId = reorderEvent.getTarget();
|
|
|
|
|
2020-01-10 11:48:24 +01:00
|
|
|
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, type);
|
2019-11-22 16:50:59 +01:00
|
|
|
|
[Trunk | Monitor Service]:
1. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java && SectionController.java && IndicatorController.java:
a. Comment logs for get requests.
b. Use "ForbiddenException" instead of "AccessDeniedException"
c. On /save, if full entity has id (already in DB), if not found in DB throw EntityNotFoundException.
d. Get children (e.g. when saving a Topic, get its categories) from DB.
2. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java:
In /reorder, if there are in DB, ids that are missing from reordered list, do reordering and add in the end of list the missing ids.
3. ReorderEvent.java: [NEW] Added class ReorderEvent with fields "action" (String), "target" (String), "ids" (List<String>) (used in IndicatorController.java).
4. IndicatorController.java:
a. In /reorder, @RequestBody changed from List<String> indicators to ReorderEvent reorderEvent.
b. If there are in DB, ids that are missing from reordered list AND missing id is not moved to other section (action = removed and target = missing id), do reordering and add in the end of list the missing ids.
5. ExceptionsHandler.java: exception handler methods "invalidInput()", "nullPointerException()", "notFoundException()" moved to "Admin Tools Library" - "accessDeniedException()" is removed.
6. responses/ExceptionResponse.java: File and folder deleted (moved to "Admin Tools Library").
7. RolesUtils.java: Added method "isLoggedIn()" (checks if no roles for user, or user has role "ROLE_ANONYMOUS").
2020-12-09 15:24:27 +01:00
|
|
|
List<String> oldIndicators = section.getIndicators();
|
|
|
|
for (String indicatorId : oldIndicators) {
|
|
|
|
if ((!actionType.equals("removed") || !targetId.equals(indicatorId)) && !indicators.contains(indicatorId)) {
|
|
|
|
indicators.add(indicatorId);
|
|
|
|
}
|
|
|
|
}
|
2020-01-10 11:48:24 +01:00
|
|
|
section.setIndicators(indicators);
|
|
|
|
|
2019-11-26 12:08:36 +01:00
|
|
|
List<Indicator> indicatorsFull = new ArrayList<>();
|
2024-03-06 00:48:31 +01:00
|
|
|
for (String indicatorId : indicators) {
|
[Trunk | Monitor Service]:
1. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java && SectionController.java && IndicatorController.java:
a. Comment logs for get requests.
b. Use "ForbiddenException" instead of "AccessDeniedException"
c. On /save, if full entity has id (already in DB), if not found in DB throw EntityNotFoundException.
d. Get children (e.g. when saving a Topic, get its categories) from DB.
2. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java:
In /reorder, if there are in DB, ids that are missing from reordered list, do reordering and add in the end of list the missing ids.
3. ReorderEvent.java: [NEW] Added class ReorderEvent with fields "action" (String), "target" (String), "ids" (List<String>) (used in IndicatorController.java).
4. IndicatorController.java:
a. In /reorder, @RequestBody changed from List<String> indicators to ReorderEvent reorderEvent.
b. If there are in DB, ids that are missing from reordered list AND missing id is not moved to other section (action = removed and target = missing id), do reordering and add in the end of list the missing ids.
5. ExceptionsHandler.java: exception handler methods "invalidInput()", "nullPointerException()", "notFoundException()" moved to "Admin Tools Library" - "accessDeniedException()" is removed.
6. responses/ExceptionResponse.java: File and folder deleted (moved to "Admin Tools Library").
7. RolesUtils.java: Added method "isLoggedIn()" (checks if no roles for user, or user has role "ROLE_ANONYMOUS").
2020-12-09 15:24:27 +01:00
|
|
|
Indicator indicator = indicatorDAO.findById(indicatorId);
|
2024-03-06 00:48:31 +01:00
|
|
|
if (indicator == null) {
|
[Trunk | Monitor Service]:
1. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java && SectionController.java && IndicatorController.java:
a. Comment logs for get requests.
b. Use "ForbiddenException" instead of "AccessDeniedException"
c. On /save, if full entity has id (already in DB), if not found in DB throw EntityNotFoundException.
d. Get children (e.g. when saving a Topic, get its categories) from DB.
2. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java:
In /reorder, if there are in DB, ids that are missing from reordered list, do reordering and add in the end of list the missing ids.
3. ReorderEvent.java: [NEW] Added class ReorderEvent with fields "action" (String), "target" (String), "ids" (List<String>) (used in IndicatorController.java).
4. IndicatorController.java:
a. In /reorder, @RequestBody changed from List<String> indicators to ReorderEvent reorderEvent.
b. If there are in DB, ids that are missing from reordered list AND missing id is not moved to other section (action = removed and target = missing id), do reordering and add in the end of list the missing ids.
5. ExceptionsHandler.java: exception handler methods "invalidInput()", "nullPointerException()", "notFoundException()" moved to "Admin Tools Library" - "accessDeniedException()" is removed.
6. responses/ExceptionResponse.java: File and folder deleted (moved to "Admin Tools Library").
7. RolesUtils.java: Added method "isLoggedIn()" (checks if no roles for user, or user has role "ROLE_ANONYMOUS").
2020-12-09 15:24:27 +01:00
|
|
|
// EXCEPTION - Indicator not found
|
|
|
|
throw new EntityNotFoundException("Reorder indicators: Indicator with id: " + indicatorId + " not found");
|
|
|
|
}
|
|
|
|
indicatorsFull.add(indicator);
|
2019-11-26 12:08:36 +01:00
|
|
|
}
|
[Trunk | Monitor Service]:
1. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java && SectionController.java && IndicatorController.java:
a. Comment logs for get requests.
b. Use "ForbiddenException" instead of "AccessDeniedException"
c. On /save, if full entity has id (already in DB), if not found in DB throw EntityNotFoundException.
d. Get children (e.g. when saving a Topic, get its categories) from DB.
2. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java:
In /reorder, if there are in DB, ids that are missing from reordered list, do reordering and add in the end of list the missing ids.
3. ReorderEvent.java: [NEW] Added class ReorderEvent with fields "action" (String), "target" (String), "ids" (List<String>) (used in IndicatorController.java).
4. IndicatorController.java:
a. In /reorder, @RequestBody changed from List<String> indicators to ReorderEvent reorderEvent.
b. If there are in DB, ids that are missing from reordered list AND missing id is not moved to other section (action = removed and target = missing id), do reordering and add in the end of list the missing ids.
5. ExceptionsHandler.java: exception handler methods "invalidInput()", "nullPointerException()", "notFoundException()" moved to "Admin Tools Library" - "accessDeniedException()" is removed.
6. responses/ExceptionResponse.java: File and folder deleted (moved to "Admin Tools Library").
7. RolesUtils.java: Added method "isLoggedIn()" (checks if no roles for user, or user has role "ROLE_ANONYMOUS").
2020-12-09 15:24:27 +01:00
|
|
|
|
|
|
|
sectionDAO.save(section);
|
|
|
|
log.debug("Indicators reordered!");
|
|
|
|
|
2019-11-26 12:08:36 +01:00
|
|
|
return indicatorsFull;
|
2024-03-14 18:01:28 +01:00
|
|
|
}*/
|
2019-12-19 16:04:25 +01:00
|
|
|
|
2020-11-11 13:45:59 +01:00
|
|
|
@PreAuthorize("isAuthenticated()")
|
|
|
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/change-visibility", method = RequestMethod.POST)
|
2022-09-14 17:02:47 +02:00
|
|
|
public Indicator changeIndicatorVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
2024-03-06 00:48:31 +01:00
|
|
|
@PathVariable("topicId") String topicId,
|
|
|
|
@PathVariable("categoryId") String categoryId,
|
|
|
|
@PathVariable("subcategoryId") String subcategoryId,
|
|
|
|
@PathVariable("sectionId") String sectionId,
|
|
|
|
@PathVariable("indicatorId") String indicatorId,
|
|
|
|
@RequestParam("visibility") Visibility visibility) {
|
|
|
|
log.debug("change indicator visibility: " + visibility);
|
|
|
|
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId + " - Indicator: " + indicatorId);
|
2024-03-14 18:01:28 +01:00
|
|
|
Stakeholder stakeholder = this.stakeholderService.findById(stakeholderId);
|
|
|
|
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
|
|
|
Category category = this.categoryService.findByPath(topic, categoryId);
|
|
|
|
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
|
|
|
Section section = this.sectionService.findByPath(subCategory, sectionId);
|
|
|
|
Indicator indicator = this.indicatorService.findByPath(section, indicatorId);
|
|
|
|
return this.indicatorService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), indicator, visibility);
|
2020-06-22 21:58:40 +02:00
|
|
|
}
|
2019-11-22 16:50:59 +01:00
|
|
|
}
|