[Trunk | Monitor Service]:

1. TopicController.java & CategoryController.java & SubCategoryController.java: New methods for reorder added.
2. CategoryController.java: Method "checkForExceptions()" added.
3. IndicatorController.java: [Bug Fix] When updating a default indicator and all indicators based on that are updated too, set description field when needed (not name again).
This commit is contained in:
Konstantina Galouni 2020-06-25 09:55:46 +00:00
parent 0f929b581d
commit 78913b0140
4 changed files with 93 additions and 1 deletions

View File

@ -320,6 +320,27 @@ public class CategoryController {
return true;
}
@RequestMapping(value = "/{stakeholderId}/{topicId}/reorder", method = RequestMethod.POST)
public List<Category> reorderCategories(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@RequestBody List<String> categories) {
log.debug("reorder categories");
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId);
Topic<String> topic = checkForExceptions(stakeholderId, topicId);
topic.setCategories(categories);
topicDAO.save(topic);
log.debug("Categories reordered!");
List<Category> categoriesFull = new ArrayList<>();
for(String categoryId : categories) {
categoriesFull.add(categoryDAO.findById(categoryId));
}
return categoriesFull;
}
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/toggle-status", method = RequestMethod.POST)
public Boolean toggleCategoryStatus(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@ -387,6 +408,30 @@ public class CategoryController {
}
}
private Topic checkForExceptions(String stakeholderId, String topicId) {
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder == null) {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("checkForExceptions category: Stakeholder with id: " + stakeholderId + " not found");
}
Topic<String> topic = topicDAO.findById(topicId);
if(topic == null) {
// EXCEPTION - Topic not found
throw new EntityNotFoundException("checkForExceptions category: Topic with id: "+topicId+" not found");
}
if(!stakeholder.getTopics().contains(topicId)) {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
throw new PathNotValidException("checkForExceptions category: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
}
return topic;
}
public void deleteTree(Topic topic) {
List<String> categories = topic.getCategories();
for(String categoryId : categories) {

View File

@ -122,7 +122,7 @@ public class IndicatorController {
if(indicator.getDescription() != null && !indicator.getDescription().equals(indicatorBasedOnDefault.getDescription())
&& (oldIndicator.getDescription() == null || oldIndicator.getDescription().equals(indicatorBasedOnDefault.getDescription()))) {
indicatorBasedOnDefault.setName(indicator.getName());
indicatorBasedOnDefault.setDescription(indicator.getDescription());
changed = true;
}

View File

@ -297,6 +297,28 @@ public class SubCategoryController {
return true;
}
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/reorder", method = RequestMethod.POST)
public List<SubCategory> reorderSubCategories(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@RequestBody List<String> subCategories) {
log.debug("reorder subCategories");
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
Category<String> category = checkForExceptions(stakeholderId, topicId, categoryId);
category.setSubCategories(subCategories);
categoryDAO.save(category);
log.debug("SubCategories reordered!");
List<SubCategory> subCategoriesFull = new ArrayList<>();
for(String subCategoryId : subCategories) {
subCategoriesFull.add(subCategoryDAO.findById(subCategoryId));
}
return subCategoriesFull;
}
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/toggle-status", method = RequestMethod.POST)
public Boolean toggleSubCategoryStatus(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,

View File

@ -297,6 +297,31 @@ public class TopicController {
return true;
}
@RequestMapping(value = "/{stakeholderId}/reorder", method = RequestMethod.POST)
public List<Topic> reorderTopics(@PathVariable("stakeholderId") String stakeholderId,
@RequestBody List<String> topics) {
log.debug("reorder topics");
log.debug("Stakeholder: "+stakeholderId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder != null) {
stakeholder.setTopics(topics);
stakeholderDAO.save(stakeholder);
log.debug("Topics reordered!");
List<Topic> topicsFull = new ArrayList<>();
for (String topicId : topics) {
topicsFull.add(topicDAO.findById(topicId));
}
return topicsFull;
} else {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("Reorder topics: Stakeholder with id: "+stakeholderId+" not found");
}
}
@RequestMapping(value = "/{stakeholderId}/{topicId}/toggle-status", method = RequestMethod.POST)
public Boolean toggleTopicStatus(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId) {