uoa-monitor-service/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java

574 lines
26 KiB
Java
Raw Normal View History

package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
import eu.dnetlib.uoamonitorservice.dao.*;
import eu.dnetlib.uoamonitorservice.entities.*;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
[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
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
@RestController
@CrossOrigin(origins = "*")
public class SubCategoryController {
private final Logger log = LogManager.getLogger(this.getClass());
@Autowired
private RolesUtils rolesUtils;
@Autowired
private StakeholderDAO stakeholderDAO;
@Autowired
private TopicDAO topicDAO;
@Autowired
private CategoryDAO categoryDAO;
@Autowired
private SubCategoryDAO subCategoryDAO;
@Autowired
private SectionDAO sectionDAO;
@Autowired
private IndicatorDAO indicatorDAO;
@Autowired
private SectionController sectionController;
public SubCategory<Section<Indicator>> buildSubCategory(SubCategory<Section<Indicator>> subcategoryFull) {
SubCategory<String> subCategory = new SubCategory<>(subcategoryFull);
List<String> sectionCharts = new ArrayList<>();
List<Section<Indicator>> sectionChartsFull = new ArrayList<>();
for(Section section : subcategoryFull.getCharts()) {
Section<Indicator> sectionFull = sectionController.buildSection(section);
sectionChartsFull.add(sectionFull);
sectionCharts.add(sectionFull.getId());
}
subcategoryFull.setCharts(sectionChartsFull);
subCategory.setCharts(sectionCharts);
List<String> sectionNumbers = new ArrayList<>();
List<Section<Indicator>> sectionNumbersFull = new ArrayList<>();
for(Section section : subcategoryFull.getNumbers()) {
Section<Indicator> sectionFull = sectionController.buildSection(section);
sectionNumbersFull.add(sectionFull);
sectionNumbers.add(sectionFull.getId());
}
subcategoryFull.setNumbers(sectionNumbersFull);
subCategory.setNumbers(sectionNumbers);
Date date = new Date();
subCategory.setCreationDate(date);
subCategory.setUpdateDate(date);
subcategoryFull.setCreationDate(date);
subcategoryFull.setUpdateDate(date);
1. pom.xml: Add dependency for "uoa-help-texts-library" (will be renamed). 2. UoaMonitorServiceApplication.java: Add @PropertySource path used in dl170. 3. MongoConnection.java: @EnableMongoRepositories not only from: eu.dnetlib.uoamonitorservice.dao, but also: eu.dnetlib.uoahelptexts.dao. 4. GoogleConfig.java & MailConfig.java: [Deleted]: Functionality available on library project. 5. EmailController.java: [New]: Used for contact-us page in portal. 6. ExceptionsHandler.java & /controllers/: Add more and detailed logs. 7. Stakeholder.java: a. Field 'logoUrl' added. b. Method 'getType()' returns type.name() and 'setType()' gets String and converts it into StakeholderType. 8. Topic.java & Category.java & SubCategory.java & Indicator.java: a. Field 'boolean isDefault' changed to 'String defaultId'. b. Method copyFromDefault() added to create a clone from default entity (topic, category, subcategory, indicator). 9. Category.java & SubCategory.java: Field 'String description' added. 10. SubCategory.java: Field 'String stakeholderId' added | method createOverviewSubCategory(Category) added. 11. Indicator.java & IndicatorPath.java: Method 'getType()' returns type.name() and 'setType()' gets String and converts it into IndicatorType / IndicatorPathType. 12. IndicatorPath.java: Constructor and copy constructor added. 13. StakeholderDAO.java & MongoDBStakeholderDAO.java: a. Method findByIsDefaultProfile() changed to: findByDefaultId() & findByDefaultIdNot(). b. Method findByIsDefaultProfileAndType() changed to: findByDefaultIdAndType() & findByDefaultIdNotAndType(). 14. SubCategoryDAO.java & MongoDBSubCategoryDAO.java & IndicatorDAO.java & MongoDBSubCategoryDAO.java: Method 'findByDefaultId()' added. 15. StakeholderController.java: Handle creationDate and updateDate | Add more exceptional cases. 16. TopicController.java: a. Helper method 'onSaveDefaultTopic()' added (save cloned topic on stakeholders based on this default Stakeholder). b. Helper method 'onUpdateDefaultTopic()' added (update cloned topics based on this default topic). 17. CategoryController.java: a. Remove 'subCategory.setIsDefault(true);' when a category is created. b. Helper method 'onSaveDefaultCategory()' added (save cloned category on topics based on this default Topic). c. Helper method 'onUpdateDefaultCategory()' added (update cloned categories based on this default category). 18. SubCategoryController.java: a. Helper method 'onSaveDefaultSubCategory()' added (save cloned subCategory on topics based on this default Category). b. Helper method 'onUpdateDefaultSubCategory()' added (update cloned subCategories based on this default subCategory). 19. IndicatorController.java: a. Helper method 'onSaveDefaultIndicator()' added (save cloned indicator on subCategories based on this default SubCategory). b. Helper method 'onUpdateDefaultIndicator()' added (update cloned indicators based on this default indicator). c. Helper method 'parameterMapping()' added to map correct parameter values on parameters depending on stakeholder info. d. Method 'toggleIndicatorStatus()' added to toggle 'isActive' field. e. Method 'toggleIndicatorAccess()' added to toggle 'isPublic' field. f. Helper method 'toggleIndicator()' added to update indicator when a field is toggled.
2019-12-19 16:04:25 +01:00
subCategoryDAO.save(subCategory);
1. pom.xml: Add dependency for "uoa-help-texts-library" (will be renamed). 2. UoaMonitorServiceApplication.java: Add @PropertySource path used in dl170. 3. MongoConnection.java: @EnableMongoRepositories not only from: eu.dnetlib.uoamonitorservice.dao, but also: eu.dnetlib.uoahelptexts.dao. 4. GoogleConfig.java & MailConfig.java: [Deleted]: Functionality available on library project. 5. EmailController.java: [New]: Used for contact-us page in portal. 6. ExceptionsHandler.java & /controllers/: Add more and detailed logs. 7. Stakeholder.java: a. Field 'logoUrl' added. b. Method 'getType()' returns type.name() and 'setType()' gets String and converts it into StakeholderType. 8. Topic.java & Category.java & SubCategory.java & Indicator.java: a. Field 'boolean isDefault' changed to 'String defaultId'. b. Method copyFromDefault() added to create a clone from default entity (topic, category, subcategory, indicator). 9. Category.java & SubCategory.java: Field 'String description' added. 10. SubCategory.java: Field 'String stakeholderId' added | method createOverviewSubCategory(Category) added. 11. Indicator.java & IndicatorPath.java: Method 'getType()' returns type.name() and 'setType()' gets String and converts it into IndicatorType / IndicatorPathType. 12. IndicatorPath.java: Constructor and copy constructor added. 13. StakeholderDAO.java & MongoDBStakeholderDAO.java: a. Method findByIsDefaultProfile() changed to: findByDefaultId() & findByDefaultIdNot(). b. Method findByIsDefaultProfileAndType() changed to: findByDefaultIdAndType() & findByDefaultIdNotAndType(). 14. SubCategoryDAO.java & MongoDBSubCategoryDAO.java & IndicatorDAO.java & MongoDBSubCategoryDAO.java: Method 'findByDefaultId()' added. 15. StakeholderController.java: Handle creationDate and updateDate | Add more exceptional cases. 16. TopicController.java: a. Helper method 'onSaveDefaultTopic()' added (save cloned topic on stakeholders based on this default Stakeholder). b. Helper method 'onUpdateDefaultTopic()' added (update cloned topics based on this default topic). 17. CategoryController.java: a. Remove 'subCategory.setIsDefault(true);' when a category is created. b. Helper method 'onSaveDefaultCategory()' added (save cloned category on topics based on this default Topic). c. Helper method 'onUpdateDefaultCategory()' added (update cloned categories based on this default category). 18. SubCategoryController.java: a. Helper method 'onSaveDefaultSubCategory()' added (save cloned subCategory on topics based on this default Category). b. Helper method 'onUpdateDefaultSubCategory()' added (update cloned subCategories based on this default subCategory). 19. IndicatorController.java: a. Helper method 'onSaveDefaultIndicator()' added (save cloned indicator on subCategories based on this default SubCategory). b. Helper method 'onUpdateDefaultIndicator()' added (update cloned indicators based on this default indicator). c. Helper method 'parameterMapping()' added to map correct parameter values on parameters depending on stakeholder info. d. Method 'toggleIndicatorStatus()' added to toggle 'isActive' field. e. Method 'toggleIndicatorAccess()' added to toggle 'isPublic' field. f. Helper method 'toggleIndicator()' added to update indicator when a field is toggled.
2019-12-19 16:04:25 +01:00
subcategoryFull.setId(subCategory.getId());
return subcategoryFull;
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/save", method = RequestMethod.POST)
public SubCategory<Section<Indicator>> saveSubCategory(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@RequestBody SubCategory<Section<Indicator>> subcategoryFull) {
log.debug("save subcategory");
1. pom.xml: Add dependency for "uoa-help-texts-library" (will be renamed). 2. UoaMonitorServiceApplication.java: Add @PropertySource path used in dl170. 3. MongoConnection.java: @EnableMongoRepositories not only from: eu.dnetlib.uoamonitorservice.dao, but also: eu.dnetlib.uoahelptexts.dao. 4. GoogleConfig.java & MailConfig.java: [Deleted]: Functionality available on library project. 5. EmailController.java: [New]: Used for contact-us page in portal. 6. ExceptionsHandler.java & /controllers/: Add more and detailed logs. 7. Stakeholder.java: a. Field 'logoUrl' added. b. Method 'getType()' returns type.name() and 'setType()' gets String and converts it into StakeholderType. 8. Topic.java & Category.java & SubCategory.java & Indicator.java: a. Field 'boolean isDefault' changed to 'String defaultId'. b. Method copyFromDefault() added to create a clone from default entity (topic, category, subcategory, indicator). 9. Category.java & SubCategory.java: Field 'String description' added. 10. SubCategory.java: Field 'String stakeholderId' added | method createOverviewSubCategory(Category) added. 11. Indicator.java & IndicatorPath.java: Method 'getType()' returns type.name() and 'setType()' gets String and converts it into IndicatorType / IndicatorPathType. 12. IndicatorPath.java: Constructor and copy constructor added. 13. StakeholderDAO.java & MongoDBStakeholderDAO.java: a. Method findByIsDefaultProfile() changed to: findByDefaultId() & findByDefaultIdNot(). b. Method findByIsDefaultProfileAndType() changed to: findByDefaultIdAndType() & findByDefaultIdNotAndType(). 14. SubCategoryDAO.java & MongoDBSubCategoryDAO.java & IndicatorDAO.java & MongoDBSubCategoryDAO.java: Method 'findByDefaultId()' added. 15. StakeholderController.java: Handle creationDate and updateDate | Add more exceptional cases. 16. TopicController.java: a. Helper method 'onSaveDefaultTopic()' added (save cloned topic on stakeholders based on this default Stakeholder). b. Helper method 'onUpdateDefaultTopic()' added (update cloned topics based on this default topic). 17. CategoryController.java: a. Remove 'subCategory.setIsDefault(true);' when a category is created. b. Helper method 'onSaveDefaultCategory()' added (save cloned category on topics based on this default Topic). c. Helper method 'onUpdateDefaultCategory()' added (update cloned categories based on this default category). 18. SubCategoryController.java: a. Helper method 'onSaveDefaultSubCategory()' added (save cloned subCategory on topics based on this default Category). b. Helper method 'onUpdateDefaultSubCategory()' added (update cloned subCategories based on this default subCategory). 19. IndicatorController.java: a. Helper method 'onSaveDefaultIndicator()' added (save cloned indicator on subCategories based on this default SubCategory). b. Helper method 'onUpdateDefaultIndicator()' added (update cloned indicators based on this default indicator). c. Helper method 'parameterMapping()' added to map correct parameter values on parameters depending on stakeholder info. d. Method 'toggleIndicatorStatus()' added to toggle 'isActive' field. e. Method 'toggleIndicatorAccess()' added to toggle 'isPublic' field. f. Helper method 'toggleIndicator()' added to update indicator when a field is toggled.
2019-12-19 16:04:25 +01:00
log.debug("Alias: "+subcategoryFull.getAlias() + " - Id: "+subcategoryFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
Category category = checkForExceptions(stakeholderId, topicId, categoryId);
SubCategory<String> subCategory = new SubCategory<>(subcategoryFull);
Date date = new Date();
subCategory.setUpdateDate(date);
subcategoryFull.setUpdateDate(date);
[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> chartSections = new ArrayList<>();
List<String> numberSections = new ArrayList<>();
SubCategory<String> oldSubcategory = null;
if(subcategoryFull.getId() != null) {
oldSubcategory = subCategoryDAO.findById(subcategoryFull.getId());
[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
if(oldSubcategory == null) {
// EXCEPTION - SubCategory not found
throw new EntityNotFoundException("save subcategory: SubCategory with id: " + subcategoryFull.getId() + " not found");
}
for(String chartSectionId : oldSubcategory.getCharts()) {
Section section = sectionDAO.findById(chartSectionId);
if (section == null) {
// EXCEPTION - Section not found
throw new EntityNotFoundException("Save subcategory: Chart section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategory.getId()+")");
}
chartSections.add(section.getId());
}
for(String numberSectionId : oldSubcategory.getNumbers()) {
Section section = sectionDAO.findById(numberSectionId);
if (section == null) {
// EXCEPTION - Section not found
throw new EntityNotFoundException("Save subcategory: Number section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategory.getId()+")");
}
numberSections.add(section.getId());
}
} else { // subcategory does not exist in DB
subCategory.setCreationDate(date);
subcategoryFull.setCreationDate(date);
[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
for(Section chartSection : subcategoryFull.getCharts()) {
chartSections.add(chartSection.getId());
}
for(Section numberSection : subcategoryFull.getNumbers()) {
numberSections.add(numberSection.getId());
}
}
// List<String> charts = new ArrayList<>();
// for(Indicator chart : subcategoryFull.getCharts()) {
// charts.add(chart.getId());
// }
// subCategory.setCharts(charts);
//
// List<String> numbers = new ArrayList<>();
// for(Indicator numbr : subcategoryFull.getNumbers()) {
// numbers.add(numbr.getId());
// }
// subCategory.setNumbers(numbers);
[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
subCategory.setCharts(chartSections);
subCategory.setNumbers(numberSections);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder.getDefaultId() == null) {
if(subcategoryFull.getId() == null) {
subCategoryDAO.save(subCategory);
onSaveDefaultSubCategory(subCategory, categoryId);
} else {
onUpdateDefaultSubCategory(subCategory, oldSubcategory);
subCategoryDAO.save(subCategory);
}
} else {
subCategoryDAO.save(subCategory);
}
List<String> subcategories = category.getSubCategories();
int index = subcategories.indexOf(subCategory.getId());
if(index == -1) {
subcategories.add(subCategory.getId());
categoryDAO.save(category);
log.debug("Subcategory saved!");
subcategoryFull.setId(subCategory.getId());
}
chartSections = null;
numberSections = null;
subCategory = null;
return subcategoryFull;
}
1. pom.xml: Add dependency for "uoa-help-texts-library" (will be renamed). 2. UoaMonitorServiceApplication.java: Add @PropertySource path used in dl170. 3. MongoConnection.java: @EnableMongoRepositories not only from: eu.dnetlib.uoamonitorservice.dao, but also: eu.dnetlib.uoahelptexts.dao. 4. GoogleConfig.java & MailConfig.java: [Deleted]: Functionality available on library project. 5. EmailController.java: [New]: Used for contact-us page in portal. 6. ExceptionsHandler.java & /controllers/: Add more and detailed logs. 7. Stakeholder.java: a. Field 'logoUrl' added. b. Method 'getType()' returns type.name() and 'setType()' gets String and converts it into StakeholderType. 8. Topic.java & Category.java & SubCategory.java & Indicator.java: a. Field 'boolean isDefault' changed to 'String defaultId'. b. Method copyFromDefault() added to create a clone from default entity (topic, category, subcategory, indicator). 9. Category.java & SubCategory.java: Field 'String description' added. 10. SubCategory.java: Field 'String stakeholderId' added | method createOverviewSubCategory(Category) added. 11. Indicator.java & IndicatorPath.java: Method 'getType()' returns type.name() and 'setType()' gets String and converts it into IndicatorType / IndicatorPathType. 12. IndicatorPath.java: Constructor and copy constructor added. 13. StakeholderDAO.java & MongoDBStakeholderDAO.java: a. Method findByIsDefaultProfile() changed to: findByDefaultId() & findByDefaultIdNot(). b. Method findByIsDefaultProfileAndType() changed to: findByDefaultIdAndType() & findByDefaultIdNotAndType(). 14. SubCategoryDAO.java & MongoDBSubCategoryDAO.java & IndicatorDAO.java & MongoDBSubCategoryDAO.java: Method 'findByDefaultId()' added. 15. StakeholderController.java: Handle creationDate and updateDate | Add more exceptional cases. 16. TopicController.java: a. Helper method 'onSaveDefaultTopic()' added (save cloned topic on stakeholders based on this default Stakeholder). b. Helper method 'onUpdateDefaultTopic()' added (update cloned topics based on this default topic). 17. CategoryController.java: a. Remove 'subCategory.setIsDefault(true);' when a category is created. b. Helper method 'onSaveDefaultCategory()' added (save cloned category on topics based on this default Topic). c. Helper method 'onUpdateDefaultCategory()' added (update cloned categories based on this default category). 18. SubCategoryController.java: a. Helper method 'onSaveDefaultSubCategory()' added (save cloned subCategory on topics based on this default Category). b. Helper method 'onUpdateDefaultSubCategory()' added (update cloned subCategories based on this default subCategory). 19. IndicatorController.java: a. Helper method 'onSaveDefaultIndicator()' added (save cloned indicator on subCategories based on this default SubCategory). b. Helper method 'onUpdateDefaultIndicator()' added (update cloned indicators based on this default indicator). c. Helper method 'parameterMapping()' added to map correct parameter values on parameters depending on stakeholder info. d. Method 'toggleIndicatorStatus()' added to toggle 'isActive' field. e. Method 'toggleIndicatorAccess()' added to toggle 'isPublic' field. f. Helper method 'toggleIndicator()' added to update indicator when a field is toggled.
2019-12-19 16:04:25 +01:00
public void onSaveDefaultSubCategory(SubCategory subCategory, String categoryId) {
log.debug("On save default subCategory");
List<Category> categories = categoryDAO.findByDefaultId(categoryId);
for(Category category : categories) {
SubCategory subCategoryNew = new SubCategory();
subCategoryNew.copyFromDefault(subCategory);
subCategoryDAO.save(subCategoryNew);
List<String> subCategories = category.getSubCategories();
subCategories.add(subCategoryNew.getId());
categoryDAO.save(category);
}
}
public void onUpdateDefaultSubCategory(SubCategory subCategory, SubCategory oldSubcategory) {
1. pom.xml: Add dependency for "uoa-help-texts-library" (will be renamed). 2. UoaMonitorServiceApplication.java: Add @PropertySource path used in dl170. 3. MongoConnection.java: @EnableMongoRepositories not only from: eu.dnetlib.uoamonitorservice.dao, but also: eu.dnetlib.uoahelptexts.dao. 4. GoogleConfig.java & MailConfig.java: [Deleted]: Functionality available on library project. 5. EmailController.java: [New]: Used for contact-us page in portal. 6. ExceptionsHandler.java & /controllers/: Add more and detailed logs. 7. Stakeholder.java: a. Field 'logoUrl' added. b. Method 'getType()' returns type.name() and 'setType()' gets String and converts it into StakeholderType. 8. Topic.java & Category.java & SubCategory.java & Indicator.java: a. Field 'boolean isDefault' changed to 'String defaultId'. b. Method copyFromDefault() added to create a clone from default entity (topic, category, subcategory, indicator). 9. Category.java & SubCategory.java: Field 'String description' added. 10. SubCategory.java: Field 'String stakeholderId' added | method createOverviewSubCategory(Category) added. 11. Indicator.java & IndicatorPath.java: Method 'getType()' returns type.name() and 'setType()' gets String and converts it into IndicatorType / IndicatorPathType. 12. IndicatorPath.java: Constructor and copy constructor added. 13. StakeholderDAO.java & MongoDBStakeholderDAO.java: a. Method findByIsDefaultProfile() changed to: findByDefaultId() & findByDefaultIdNot(). b. Method findByIsDefaultProfileAndType() changed to: findByDefaultIdAndType() & findByDefaultIdNotAndType(). 14. SubCategoryDAO.java & MongoDBSubCategoryDAO.java & IndicatorDAO.java & MongoDBSubCategoryDAO.java: Method 'findByDefaultId()' added. 15. StakeholderController.java: Handle creationDate and updateDate | Add more exceptional cases. 16. TopicController.java: a. Helper method 'onSaveDefaultTopic()' added (save cloned topic on stakeholders based on this default Stakeholder). b. Helper method 'onUpdateDefaultTopic()' added (update cloned topics based on this default topic). 17. CategoryController.java: a. Remove 'subCategory.setIsDefault(true);' when a category is created. b. Helper method 'onSaveDefaultCategory()' added (save cloned category on topics based on this default Topic). c. Helper method 'onUpdateDefaultCategory()' added (update cloned categories based on this default category). 18. SubCategoryController.java: a. Helper method 'onSaveDefaultSubCategory()' added (save cloned subCategory on topics based on this default Category). b. Helper method 'onUpdateDefaultSubCategory()' added (update cloned subCategories based on this default subCategory). 19. IndicatorController.java: a. Helper method 'onSaveDefaultIndicator()' added (save cloned indicator on subCategories based on this default SubCategory). b. Helper method 'onUpdateDefaultIndicator()' added (update cloned indicators based on this default indicator). c. Helper method 'parameterMapping()' added to map correct parameter values on parameters depending on stakeholder info. d. Method 'toggleIndicatorStatus()' added to toggle 'isActive' field. e. Method 'toggleIndicatorAccess()' added to toggle 'isPublic' field. f. Helper method 'toggleIndicator()' added to update indicator when a field is toggled.
2019-12-19 16:04:25 +01:00
log.debug("On update default subCategory");
List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(subCategory.getId());
boolean changed = false;
for(SubCategory subCategoryBasedOnDefault : subCategories) {
if(subCategory.getName() != null && !subCategory.getName().equals(subCategoryBasedOnDefault.getName())
&& (oldSubcategory.getName() == null || oldSubcategory.getName().equals(subCategoryBasedOnDefault.getName()))) {
subCategoryBasedOnDefault.setName(subCategory.getName());
subCategoryBasedOnDefault.setAlias(subCategory.getAlias());
1. pom.xml: Add dependency for "uoa-help-texts-library" (will be renamed). 2. UoaMonitorServiceApplication.java: Add @PropertySource path used in dl170. 3. MongoConnection.java: @EnableMongoRepositories not only from: eu.dnetlib.uoamonitorservice.dao, but also: eu.dnetlib.uoahelptexts.dao. 4. GoogleConfig.java & MailConfig.java: [Deleted]: Functionality available on library project. 5. EmailController.java: [New]: Used for contact-us page in portal. 6. ExceptionsHandler.java & /controllers/: Add more and detailed logs. 7. Stakeholder.java: a. Field 'logoUrl' added. b. Method 'getType()' returns type.name() and 'setType()' gets String and converts it into StakeholderType. 8. Topic.java & Category.java & SubCategory.java & Indicator.java: a. Field 'boolean isDefault' changed to 'String defaultId'. b. Method copyFromDefault() added to create a clone from default entity (topic, category, subcategory, indicator). 9. Category.java & SubCategory.java: Field 'String description' added. 10. SubCategory.java: Field 'String stakeholderId' added | method createOverviewSubCategory(Category) added. 11. Indicator.java & IndicatorPath.java: Method 'getType()' returns type.name() and 'setType()' gets String and converts it into IndicatorType / IndicatorPathType. 12. IndicatorPath.java: Constructor and copy constructor added. 13. StakeholderDAO.java & MongoDBStakeholderDAO.java: a. Method findByIsDefaultProfile() changed to: findByDefaultId() & findByDefaultIdNot(). b. Method findByIsDefaultProfileAndType() changed to: findByDefaultIdAndType() & findByDefaultIdNotAndType(). 14. SubCategoryDAO.java & MongoDBSubCategoryDAO.java & IndicatorDAO.java & MongoDBSubCategoryDAO.java: Method 'findByDefaultId()' added. 15. StakeholderController.java: Handle creationDate and updateDate | Add more exceptional cases. 16. TopicController.java: a. Helper method 'onSaveDefaultTopic()' added (save cloned topic on stakeholders based on this default Stakeholder). b. Helper method 'onUpdateDefaultTopic()' added (update cloned topics based on this default topic). 17. CategoryController.java: a. Remove 'subCategory.setIsDefault(true);' when a category is created. b. Helper method 'onSaveDefaultCategory()' added (save cloned category on topics based on this default Topic). c. Helper method 'onUpdateDefaultCategory()' added (update cloned categories based on this default category). 18. SubCategoryController.java: a. Helper method 'onSaveDefaultSubCategory()' added (save cloned subCategory on topics based on this default Category). b. Helper method 'onUpdateDefaultSubCategory()' added (update cloned subCategories based on this default subCategory). 19. IndicatorController.java: a. Helper method 'onSaveDefaultIndicator()' added (save cloned indicator on subCategories based on this default SubCategory). b. Helper method 'onUpdateDefaultIndicator()' added (update cloned indicators based on this default indicator). c. Helper method 'parameterMapping()' added to map correct parameter values on parameters depending on stakeholder info. d. Method 'toggleIndicatorStatus()' added to toggle 'isActive' field. e. Method 'toggleIndicatorAccess()' added to toggle 'isPublic' field. f. Helper method 'toggleIndicator()' added to update indicator when a field is toggled.
2019-12-19 16:04:25 +01:00
changed = true;
}
if(subCategory.getDescription() != null && !subCategory.getDescription().equals(subCategoryBasedOnDefault.getDescription())
&& (oldSubcategory.getDescription() == null || oldSubcategory.getDescription().equals(subCategoryBasedOnDefault.getDescription()))) {
subCategoryBasedOnDefault.setDescription(subCategory.getDescription());
1. pom.xml: Add dependency for "uoa-help-texts-library" (will be renamed). 2. UoaMonitorServiceApplication.java: Add @PropertySource path used in dl170. 3. MongoConnection.java: @EnableMongoRepositories not only from: eu.dnetlib.uoamonitorservice.dao, but also: eu.dnetlib.uoahelptexts.dao. 4. GoogleConfig.java & MailConfig.java: [Deleted]: Functionality available on library project. 5. EmailController.java: [New]: Used for contact-us page in portal. 6. ExceptionsHandler.java & /controllers/: Add more and detailed logs. 7. Stakeholder.java: a. Field 'logoUrl' added. b. Method 'getType()' returns type.name() and 'setType()' gets String and converts it into StakeholderType. 8. Topic.java & Category.java & SubCategory.java & Indicator.java: a. Field 'boolean isDefault' changed to 'String defaultId'. b. Method copyFromDefault() added to create a clone from default entity (topic, category, subcategory, indicator). 9. Category.java & SubCategory.java: Field 'String description' added. 10. SubCategory.java: Field 'String stakeholderId' added | method createOverviewSubCategory(Category) added. 11. Indicator.java & IndicatorPath.java: Method 'getType()' returns type.name() and 'setType()' gets String and converts it into IndicatorType / IndicatorPathType. 12. IndicatorPath.java: Constructor and copy constructor added. 13. StakeholderDAO.java & MongoDBStakeholderDAO.java: a. Method findByIsDefaultProfile() changed to: findByDefaultId() & findByDefaultIdNot(). b. Method findByIsDefaultProfileAndType() changed to: findByDefaultIdAndType() & findByDefaultIdNotAndType(). 14. SubCategoryDAO.java & MongoDBSubCategoryDAO.java & IndicatorDAO.java & MongoDBSubCategoryDAO.java: Method 'findByDefaultId()' added. 15. StakeholderController.java: Handle creationDate and updateDate | Add more exceptional cases. 16. TopicController.java: a. Helper method 'onSaveDefaultTopic()' added (save cloned topic on stakeholders based on this default Stakeholder). b. Helper method 'onUpdateDefaultTopic()' added (update cloned topics based on this default topic). 17. CategoryController.java: a. Remove 'subCategory.setIsDefault(true);' when a category is created. b. Helper method 'onSaveDefaultCategory()' added (save cloned category on topics based on this default Topic). c. Helper method 'onUpdateDefaultCategory()' added (update cloned categories based on this default category). 18. SubCategoryController.java: a. Helper method 'onSaveDefaultSubCategory()' added (save cloned subCategory on topics based on this default Category). b. Helper method 'onUpdateDefaultSubCategory()' added (update cloned subCategories based on this default subCategory). 19. IndicatorController.java: a. Helper method 'onSaveDefaultIndicator()' added (save cloned indicator on subCategories based on this default SubCategory). b. Helper method 'onUpdateDefaultIndicator()' added (update cloned indicators based on this default indicator). c. Helper method 'parameterMapping()' added to map correct parameter values on parameters depending on stakeholder info. d. Method 'toggleIndicatorStatus()' added to toggle 'isActive' field. e. Method 'toggleIndicatorAccess()' added to toggle 'isPublic' field. f. Helper method 'toggleIndicator()' added to update indicator when a field is toggled.
2019-12-19 16:04:25 +01:00
changed = true;
}
if(!changed) {
// break;
continue;
1. pom.xml: Add dependency for "uoa-help-texts-library" (will be renamed). 2. UoaMonitorServiceApplication.java: Add @PropertySource path used in dl170. 3. MongoConnection.java: @EnableMongoRepositories not only from: eu.dnetlib.uoamonitorservice.dao, but also: eu.dnetlib.uoahelptexts.dao. 4. GoogleConfig.java & MailConfig.java: [Deleted]: Functionality available on library project. 5. EmailController.java: [New]: Used for contact-us page in portal. 6. ExceptionsHandler.java & /controllers/: Add more and detailed logs. 7. Stakeholder.java: a. Field 'logoUrl' added. b. Method 'getType()' returns type.name() and 'setType()' gets String and converts it into StakeholderType. 8. Topic.java & Category.java & SubCategory.java & Indicator.java: a. Field 'boolean isDefault' changed to 'String defaultId'. b. Method copyFromDefault() added to create a clone from default entity (topic, category, subcategory, indicator). 9. Category.java & SubCategory.java: Field 'String description' added. 10. SubCategory.java: Field 'String stakeholderId' added | method createOverviewSubCategory(Category) added. 11. Indicator.java & IndicatorPath.java: Method 'getType()' returns type.name() and 'setType()' gets String and converts it into IndicatorType / IndicatorPathType. 12. IndicatorPath.java: Constructor and copy constructor added. 13. StakeholderDAO.java & MongoDBStakeholderDAO.java: a. Method findByIsDefaultProfile() changed to: findByDefaultId() & findByDefaultIdNot(). b. Method findByIsDefaultProfileAndType() changed to: findByDefaultIdAndType() & findByDefaultIdNotAndType(). 14. SubCategoryDAO.java & MongoDBSubCategoryDAO.java & IndicatorDAO.java & MongoDBSubCategoryDAO.java: Method 'findByDefaultId()' added. 15. StakeholderController.java: Handle creationDate and updateDate | Add more exceptional cases. 16. TopicController.java: a. Helper method 'onSaveDefaultTopic()' added (save cloned topic on stakeholders based on this default Stakeholder). b. Helper method 'onUpdateDefaultTopic()' added (update cloned topics based on this default topic). 17. CategoryController.java: a. Remove 'subCategory.setIsDefault(true);' when a category is created. b. Helper method 'onSaveDefaultCategory()' added (save cloned category on topics based on this default Topic). c. Helper method 'onUpdateDefaultCategory()' added (update cloned categories based on this default category). 18. SubCategoryController.java: a. Helper method 'onSaveDefaultSubCategory()' added (save cloned subCategory on topics based on this default Category). b. Helper method 'onUpdateDefaultSubCategory()' added (update cloned subCategories based on this default subCategory). 19. IndicatorController.java: a. Helper method 'onSaveDefaultIndicator()' added (save cloned indicator on subCategories based on this default SubCategory). b. Helper method 'onUpdateDefaultIndicator()' added (update cloned indicators based on this default indicator). c. Helper method 'parameterMapping()' added to map correct parameter values on parameters depending on stakeholder info. d. Method 'toggleIndicatorStatus()' added to toggle 'isActive' field. e. Method 'toggleIndicatorAccess()' added to toggle 'isPublic' field. f. Helper method 'toggleIndicator()' added to update indicator when a field is toggled.
2019-12-19 16:04:25 +01:00
}
// subCategoryBasedOnDefault.setName(subCategory.getName());
// subCategoryBasedOnDefault.setDescription(subCategory.getDescription());
subCategoryBasedOnDefault.setUpdateDate(subCategory.getUpdateDate());
1. pom.xml: Add dependency for "uoa-help-texts-library" (will be renamed). 2. UoaMonitorServiceApplication.java: Add @PropertySource path used in dl170. 3. MongoConnection.java: @EnableMongoRepositories not only from: eu.dnetlib.uoamonitorservice.dao, but also: eu.dnetlib.uoahelptexts.dao. 4. GoogleConfig.java & MailConfig.java: [Deleted]: Functionality available on library project. 5. EmailController.java: [New]: Used for contact-us page in portal. 6. ExceptionsHandler.java & /controllers/: Add more and detailed logs. 7. Stakeholder.java: a. Field 'logoUrl' added. b. Method 'getType()' returns type.name() and 'setType()' gets String and converts it into StakeholderType. 8. Topic.java & Category.java & SubCategory.java & Indicator.java: a. Field 'boolean isDefault' changed to 'String defaultId'. b. Method copyFromDefault() added to create a clone from default entity (topic, category, subcategory, indicator). 9. Category.java & SubCategory.java: Field 'String description' added. 10. SubCategory.java: Field 'String stakeholderId' added | method createOverviewSubCategory(Category) added. 11. Indicator.java & IndicatorPath.java: Method 'getType()' returns type.name() and 'setType()' gets String and converts it into IndicatorType / IndicatorPathType. 12. IndicatorPath.java: Constructor and copy constructor added. 13. StakeholderDAO.java & MongoDBStakeholderDAO.java: a. Method findByIsDefaultProfile() changed to: findByDefaultId() & findByDefaultIdNot(). b. Method findByIsDefaultProfileAndType() changed to: findByDefaultIdAndType() & findByDefaultIdNotAndType(). 14. SubCategoryDAO.java & MongoDBSubCategoryDAO.java & IndicatorDAO.java & MongoDBSubCategoryDAO.java: Method 'findByDefaultId()' added. 15. StakeholderController.java: Handle creationDate and updateDate | Add more exceptional cases. 16. TopicController.java: a. Helper method 'onSaveDefaultTopic()' added (save cloned topic on stakeholders based on this default Stakeholder). b. Helper method 'onUpdateDefaultTopic()' added (update cloned topics based on this default topic). 17. CategoryController.java: a. Remove 'subCategory.setIsDefault(true);' when a category is created. b. Helper method 'onSaveDefaultCategory()' added (save cloned category on topics based on this default Topic). c. Helper method 'onUpdateDefaultCategory()' added (update cloned categories based on this default category). 18. SubCategoryController.java: a. Helper method 'onSaveDefaultSubCategory()' added (save cloned subCategory on topics based on this default Category). b. Helper method 'onUpdateDefaultSubCategory()' added (update cloned subCategories based on this default subCategory). 19. IndicatorController.java: a. Helper method 'onSaveDefaultIndicator()' added (save cloned indicator on subCategories based on this default SubCategory). b. Helper method 'onUpdateDefaultIndicator()' added (update cloned indicators based on this default indicator). c. Helper method 'parameterMapping()' added to map correct parameter values on parameters depending on stakeholder info. d. Method 'toggleIndicatorStatus()' added to toggle 'isActive' field. e. Method 'toggleIndicatorAccess()' added to toggle 'isPublic' field. f. Helper method 'toggleIndicator()' added to update indicator when a field is toggled.
2019-12-19 16:04:25 +01:00
subCategoryDAO.save(subCategoryBasedOnDefault);
}
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/delete", method = RequestMethod.DELETE)
public boolean deleteSubCategory(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@RequestParam(required = false) String children) {
log.debug("delete subcategory");
1. pom.xml: Add dependency for "uoa-help-texts-library" (will be renamed). 2. UoaMonitorServiceApplication.java: Add @PropertySource path used in dl170. 3. MongoConnection.java: @EnableMongoRepositories not only from: eu.dnetlib.uoamonitorservice.dao, but also: eu.dnetlib.uoahelptexts.dao. 4. GoogleConfig.java & MailConfig.java: [Deleted]: Functionality available on library project. 5. EmailController.java: [New]: Used for contact-us page in portal. 6. ExceptionsHandler.java & /controllers/: Add more and detailed logs. 7. Stakeholder.java: a. Field 'logoUrl' added. b. Method 'getType()' returns type.name() and 'setType()' gets String and converts it into StakeholderType. 8. Topic.java & Category.java & SubCategory.java & Indicator.java: a. Field 'boolean isDefault' changed to 'String defaultId'. b. Method copyFromDefault() added to create a clone from default entity (topic, category, subcategory, indicator). 9. Category.java & SubCategory.java: Field 'String description' added. 10. SubCategory.java: Field 'String stakeholderId' added | method createOverviewSubCategory(Category) added. 11. Indicator.java & IndicatorPath.java: Method 'getType()' returns type.name() and 'setType()' gets String and converts it into IndicatorType / IndicatorPathType. 12. IndicatorPath.java: Constructor and copy constructor added. 13. StakeholderDAO.java & MongoDBStakeholderDAO.java: a. Method findByIsDefaultProfile() changed to: findByDefaultId() & findByDefaultIdNot(). b. Method findByIsDefaultProfileAndType() changed to: findByDefaultIdAndType() & findByDefaultIdNotAndType(). 14. SubCategoryDAO.java & MongoDBSubCategoryDAO.java & IndicatorDAO.java & MongoDBSubCategoryDAO.java: Method 'findByDefaultId()' added. 15. StakeholderController.java: Handle creationDate and updateDate | Add more exceptional cases. 16. TopicController.java: a. Helper method 'onSaveDefaultTopic()' added (save cloned topic on stakeholders based on this default Stakeholder). b. Helper method 'onUpdateDefaultTopic()' added (update cloned topics based on this default topic). 17. CategoryController.java: a. Remove 'subCategory.setIsDefault(true);' when a category is created. b. Helper method 'onSaveDefaultCategory()' added (save cloned category on topics based on this default Topic). c. Helper method 'onUpdateDefaultCategory()' added (update cloned categories based on this default category). 18. SubCategoryController.java: a. Helper method 'onSaveDefaultSubCategory()' added (save cloned subCategory on topics based on this default Category). b. Helper method 'onUpdateDefaultSubCategory()' added (update cloned subCategories based on this default subCategory). 19. IndicatorController.java: a. Helper method 'onSaveDefaultIndicator()' added (save cloned indicator on subCategories based on this default SubCategory). b. Helper method 'onUpdateDefaultIndicator()' added (update cloned indicators based on this default indicator). c. Helper method 'parameterMapping()' added to map correct parameter values on parameters depending on stakeholder info. d. Method 'toggleIndicatorStatus()' added to toggle 'isActive' field. e. Method 'toggleIndicatorAccess()' added to toggle 'isPublic' field. f. Helper method 'toggleIndicator()' added to update indicator when a field is toggled.
2019-12-19 16:04:25 +01:00
log.debug("Id: "+subcategoryId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
Category category = checkForExceptions(stakeholderId, topicId, categoryId);
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
if(subcategory != null) {
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
List<String> roles = rolesUtils.getRoles();
if(subcategory.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(roles, stakeholder.getType())) {
// EXCEPTION - Access denied
[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
throw new ForbiddenException("Delete subcategory: You are not authorized to delete a default SubCategory in stakeholder with id: "+stakeholderId);
}
List<String> subcategories = category.getSubCategories();
int index = subcategories.indexOf(subcategoryId);
if(index != -1) {
// this subCategory belongs in default profile
if(category.getDefaultId() == null && children != null) {
onDeleteDefaultSubCategory(subcategoryId, categoryId, children);
}
// for(String chartSectionId : subcategory.getCharts()) {
// Section<String> chartSection = sectionDAO.findById(chartSectionId);
// if (chartSection == null) {
// // EXCEPTION - Section not found
// throw new EntityNotFoundException("Delete SubCategory: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subcategoryId+")");
// }
//
// for (String chartId : chartSection.getIndicators()) {
// indicatorDAO.delete(chartId);
// }
// subcategory.setCharts(null);
// sectionDAO.delete(chartSectionId);
// }
//
// for(String numberSectionId : subcategory.getNumbers()) {
// Section<String> numberSection = sectionDAO.findById(numberSectionId);
// if (numberSection == null) {
// // EXCEPTION - Section not found
// throw new EntityNotFoundException("Delete SubCategory: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subcategoryId+")");
// }
//
// for (String numberId : numberSection.getIndicators()) {
// indicatorDAO.delete(numberId);
// }
// subcategory.setNumbers(null);
// sectionDAO.delete(numberSectionId);
// }
sectionController.deleteTree(subcategory);
subcategory.setCharts(null);
subcategory.setNumbers(null);
subcategories.remove(index);
categoryDAO.save(category);
subCategoryDAO.delete(subcategoryId);
log.debug("Subcategory deleted!");
} else {
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
throw new PathNotValidException("Delete subcategory: Subcategory with id: "+subcategoryId+" not found in Category: "+categoryId);
}
} else {
// EXCEPTION - SubCategory not found
throw new EntityNotFoundException("Delete subcategory: SubCategory with id: "+subcategoryId+" not found");
}
return true;
}
public boolean onDeleteDefaultSubCategory(String defaultSubCategoryId, String defaultCategoryId, String children) {
if(children.equals("delete")) {
List<Category> categories = categoryDAO.findByDefaultId(defaultCategoryId);
List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubCategoryId);
for(Category category : categories) {
Iterator<SubCategory> subCategoriesIterator = subCategories.iterator();
while(subCategoriesIterator.hasNext()) {
SubCategory subCategory = subCategoriesIterator.next();
String subCategoryId = subCategory.getId();
if(category.getSubCategories() != null && category.getSubCategories().contains(subCategoryId)) {
subCategoriesIterator.remove();
category.getSubCategories().remove(subCategoryId);
categoryDAO.save(category);
sectionController.deleteTree(subCategory);
subCategoryDAO.delete(subCategoryId);
log.debug("SubCategory with id: "+subCategoryId+" deleted!");
break;
}
}
}
} else if(children.equals("disconnect")) {
List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubCategoryId);
for(SubCategory subCategory : subCategories) {
sectionController.disConnectTree(subCategory);
subCategory.setDefaultId(null);
subCategoryDAO.save(subCategory);
log.debug("DefaultId for SubCategory with id: "+subCategory.getId()+" empty!");
}
}
return true;
}
@PreAuthorize("isAuthenticated()")
@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);
[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> oldSubcategories = category.getSubCategories();
for (String subcategoryId : oldSubcategories) {
if (!subCategories.contains(subcategoryId)) {
subCategories.add(subcategoryId);
}
}
category.setSubCategories(subCategories);
List<SubCategory> subCategoriesFull = new ArrayList<>();
for(String subCategoryId : subCategories) {
[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
SubCategory subCategory = subCategoryDAO.findById(subCategoryId);
if(subCategory == null) {
// EXCEPTION - SubCategory not found
throw new EntityNotFoundException("Reorder subCategories: subCategory with id: " + subCategoryId + " not found");
}
subCategoriesFull.add(subCategory);
}
[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
categoryDAO.save(category);
log.debug("SubCategories reordered!");
return subCategoriesFull;
}
// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/toggle-status", method = RequestMethod.POST)
// public Boolean toggleSubCategoryStatus(@PathVariable("stakeholderId") String stakeholderId,
// @PathVariable("topicId") String topicId,
// @PathVariable("categoryId") String categoryId,
// @PathVariable("subcategoryId") String subcategoryId) {
// log.debug("toggle subCategory status (isActive)");
// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
//
// SubCategory subCategory = subCategoryDAO.findById(subcategoryId);
// if (subCategory == null) {
// // EXCEPTION - SubCategory not found
// throw new EntityNotFoundException("Toggle subCategory status: SubCategory with id: "+subcategoryId+" not found");
// }
// subCategory.setIsActive(!subCategory.getIsActive());
//
// this.toggleSubCategory(stakeholderId, topicId, categoryId, subCategory);
//
// return subCategory.getIsActive();
// }
//
// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/toggle-access", method = RequestMethod.POST)
// public Boolean toggleSubCategoryAccess(@PathVariable("stakeholderId") String stakeholderId,
// @PathVariable("topicId") String topicId,
// @PathVariable("categoryId") String categoryId,
// @PathVariable("subcategoryId") String subcategoryId) {
// log.debug("toggle subCategory access (isPublic)");
// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
//
// SubCategory subCategory = subCategoryDAO.findById(subcategoryId);
// if (subCategory == null) {
// // EXCEPTION - SubCategory not found
// throw new EntityNotFoundException("Toggle subCategory access: SubCategory with id: "+subcategoryId+" not found");
// }
// subCategory.setIsPublic(!subCategory.getIsPublic());
//
// this.toggleSubCategory(stakeholderId, topicId, categoryId, subCategory);
//
// return subCategory.getIsPublic();
// }
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/change-visibility", method = RequestMethod.POST)
public SubCategory changeSubCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) {
log.debug("change subCategory visibility: "+visibility + " - toggle propagate: "+((propagate != null && propagate) ? "true" : "false"));
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
SubCategory subCategory = subCategoryDAO.findById(subcategoryId);
if (subCategory == null) {
// EXCEPTION - SubCategory not found
throw new EntityNotFoundException("Change subCategory visibility: SubCategory with id: "+subcategoryId+" not found");
}
Category category = checkForExceptions(stakeholderId, topicId, categoryId);
if (category.getSubCategories().contains(subcategoryId)) {
return changeVisibilityTree(subcategoryId, visibility, propagate);
} else {
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
throw new PathNotValidException("Toggle subCategory: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
}
}
public SubCategory changeVisibilityTree(String subCategoryId, Visibility visibility, Boolean propagate) {
SubCategory<String> subCategory = subCategoryDAO.findById(subCategoryId);
if (subCategory == null) {
// EXCEPTION - SubCategory not found
throw new EntityNotFoundException("Change subCategory visibility: SubCategory with id: " + subCategoryId + " not found");
}
SubCategory<Section> subCategoryFull = new SubCategory(subCategory);
List<Section> chartsFull = new ArrayList();
List<Section> numbersFull = new ArrayList();
if (propagate != null && propagate) {
for (String sectionId : subCategory.getCharts()) {
chartsFull.add(sectionController.changeVisibilityTree(sectionId, visibility));
}
for (String sectionId : subCategory.getNumbers()) {
numbersFull.add(sectionController.changeVisibilityTree(sectionId, visibility));
}
}
subCategory.setVisibility(visibility);
subCategoryDAO.save(subCategory);
log.debug("SubCategory toggled!");
subCategoryFull.setVisibility(visibility);
subCategoryFull.setCharts(chartsFull);
subCategoryFull.setNumbers(numbersFull);
return subCategoryFull;
}
private Category checkForExceptions(String stakeholderId, String topicId, String categoryId) {
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder == null) {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " not found");
}
List<String> roles = rolesUtils.getRoles();
if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) {
// EXCEPTION - Access denied
[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
throw new ForbiddenException("CheckForExceptions SubCategory: You are not authorized to update stakeholder with id: "+stakeholderId);
}
Topic<String> topic = topicDAO.findById(topicId);
if(topic == null) {
// EXCEPTION - Topic not found
throw new EntityNotFoundException("Save indicator: Topic with id: "+topicId+" not found");
}
if(!stakeholder.getTopics().contains(topicId)) {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
throw new PathNotValidException("Save indicator: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId);
}
Category<String> category = categoryDAO.findById(categoryId);
if(category == null) {
// EXCEPTION - Category not found
throw new EntityNotFoundException("Save indicator: Category with id: "+categoryId+" not found");
}
if(!topic.getCategories().contains(categoryId)) {
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
throw new PathNotValidException("Save indicator: Category with id: "+categoryId+" not found in Topic: "+topicId);
}
// SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
// if(subcategory == null) {
// // EXCEPTION - SubCategory not found
// throw new EntityNotFoundException("Save indicator: SubCategory with id: "+subcategoryId+" not found");
// }
//
// if (!category.getSubCategories().contains(subcategoryId)) {
// // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
// throw new PathNotValidException("Save indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
// }
return category;
}
public void deleteTree(Category category) {
List<String> subCategories = category.getSubCategories();
for(String subCategoryId : subCategories) {
SubCategory subCategory = subCategoryDAO.findById(subCategoryId);
if (subCategory == null) {
// EXCEPTION - SubCategory not found
throw new EntityNotFoundException("SubCategory delete tree: SubCategory with id: "+subCategoryId+" not found (subCategory exists in category: "+category.getId()+")");
}
sectionController.deleteTree(subCategory);
subCategoryDAO.delete(subCategoryId);
}
}
public void disConnectTree(Category category) {
List<String> subCategories = category.getSubCategories();
for(String subCategoryId : subCategories) {
SubCategory subCategory = subCategoryDAO.findById(subCategoryId);
if (subCategory == null) {
// EXCEPTION - SubCategory not found
throw new EntityNotFoundException("SubCategory disconnect tree: SubCategory with id: "+subCategoryId+" not found (subCategory exists in category: "+category.getId()+")");
}
sectionController.disConnectTree(subCategory);
subCategory.setDefaultId(null);
subCategoryDAO.save(subCategory);
}
}
}