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

580 lines
27 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 CategoryController {
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 SubCategoryController subCategoryController;
public Category<SubCategory> buildCategory(Category<SubCategory> categoryFull) {
Category<String> category = new Category<>(categoryFull);
List<String> subCategories = new ArrayList<>();
List<SubCategory> subCategoriesFull = new ArrayList<>();
for(SubCategory<Section<Indicator>> subCategory : categoryFull.getSubCategories()) {
SubCategory<Section<Indicator>> subcategoryFull = subCategoryController.buildSubCategory(subCategory);
subCategoriesFull.add(subcategoryFull);
subCategories.add(subcategoryFull.getId());
}
categoryFull.setSubCategories(subCategoriesFull);
category.setSubCategories(subCategories);
Date date = new Date();
category.setCreationDate(date);
category.setUpdateDate(date);
categoryFull.setCreationDate(date);
categoryFull.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
categoryDAO.save(category);
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
categoryFull.setId(category.getId());
return categoryFull;
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/save", method = RequestMethod.POST)
public Category<SubCategory> saveCategory(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@RequestBody Category<SubCategory> categoryFull) {
log.debug("save category");
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: "+categoryFull.getAlias() + " - Id: "+categoryFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder != null) {
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("Save Category: You are not authorized to update stakeholder with id: "+stakeholderId);
}
Category<String> oldCategory = null;
if(categoryFull.getId() != null) {
oldCategory = categoryDAO.findById(categoryFull.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(oldCategory == null) {
// EXCEPTION - Category not found
throw new EntityNotFoundException("save category: Category with id: " + categoryFull.getId() + " not found");
}
}
Topic<String> topic = topicDAO.findById(topicId);
if(topic != null) {
if(stakeholder.getTopics().contains(topicId)) {
Category<String> category = new Category<>(categoryFull);
Date date = new Date();
category.setUpdateDate(date);
categoryFull.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> subCategories = new ArrayList<>();
// if category not exists (no id), create a new default subcategory, identical to category
if(categoryFull.getId() == null) {
category.setCreationDate(date);
categoryFull.setCreationDate(date);
SubCategory<String> subCategory = new 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
subCategory.createOverviewSubCategory(categoryFull);
subCategoryDAO.save(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
List<SubCategory> subCategoriesFull = categoryFull.getSubCategories();
subCategoriesFull.add(subCategory);
for(SubCategory oldSubCategory : subCategoriesFull) {
subCategories.add(oldSubCategory.getId());
}
} else {
for(String subCategoryId : oldCategory.getSubCategories()) {
SubCategory subCategory = subCategoryDAO.findById(subCategoryId);
if (subCategory == null) {
// EXCEPTION - SubCategory not found
throw new EntityNotFoundException("Save category: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+category.getId()+")");
}
subCategories.add(subCategory.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
category.setSubCategories(subCategories);
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
if(stakeholder.getDefaultId() == null) {
if(categoryFull.getId() == null) {
categoryDAO.save(category);
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
onSaveDefaultCategory(category, topicId);
} else {
onUpdateDefaultCategory(category, oldCategory);
categoryDAO.save(category);
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
}
} else {
categoryDAO.save(category);
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
}
List<String> categories = topic.getCategories();
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
int index = categories.indexOf(category.getId());
if(index == -1) {
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
categories.add(category.getId());
topicDAO.save(topic);
log.debug("Category saved!");
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
categoryFull.setId(category.getId());
}
subCategories = null;
category = null;
} else {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
throw new PathNotValidException("Save category: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
}
} else {
// EXCEPTION - Topic not found
throw new EntityNotFoundException("Save category: Topic with id: "+topicId+" not found");
}
} else {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("Save category: Stakeholder with id: "+stakeholderId+" not found");
}
return categoryFull;
}
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 onSaveDefaultCategory(Category<String> category, String topicId) {
log.debug("On save default category");
List<Topic> topics = topicDAO.findByDefaultId(topicId);
for(Topic topic : topics) {
Category categoryNew = new Category();
categoryNew.copyFromDefault(category);
categoryDAO.save(categoryNew);
List<String> categories = topic.getCategories();
categories.add(categoryNew.getId());
topicDAO.save(topic);
}
String subCategoryOverviewId = category.getSubCategories().get(0);
SubCategory subCategoryOverview = subCategoryDAO.findById(subCategoryOverviewId);
subCategoryController.onSaveDefaultSubCategory(subCategoryOverview, category.getId());
}
public void onUpdateDefaultCategory(Category category, Category oldCategory) {
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 category");
List<Category> categories = categoryDAO.findByDefaultId(category.getId());
boolean changed = false;
for(Category categoryBasedOnDefault : categories) {
if(category.getName() != null && !category.getName().equals(categoryBasedOnDefault.getName())
&& (oldCategory.getName() == null || oldCategory.getName().equals(categoryBasedOnDefault.getName()))) {
categoryBasedOnDefault.setName(category.getName());
categoryBasedOnDefault.setAlias(category.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(category.getDescription() != null && !category.getDescription().equals(categoryBasedOnDefault.getDescription())
&& (oldCategory.getDescription() == null || oldCategory.getDescription().equals(categoryBasedOnDefault.getDescription()))) {
categoryBasedOnDefault.setDescription(category.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
}
// categoryBasedOnDefault.setName(category.getName());
// categoryBasedOnDefault.setDescription(category.getDescription());
categoryBasedOnDefault.setUpdateDate(category.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
categoryDAO.save(categoryBasedOnDefault);
}
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/delete", method = RequestMethod.DELETE)
public boolean deleteCategory(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@RequestParam(required = false) String children) {
log.debug("delete category");
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: "+categoryId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder != null) {
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("Delete category: You are not authorized to update stakeholder with id: "+stakeholderId);
}
Topic<String> topic = topicDAO.findById(topicId);
if(topic != null) {
if(stakeholder.getTopics().contains(topicId)) {
Category<String> category = categoryDAO.findById(categoryId);
if(category != null) {
if(category.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 category: You are not authorized to delete a default Category in stakeholder with id: "+stakeholderId);
}
List<String> categories = topic.getCategories();
int index = categories.indexOf(categoryId);
if(index != -1) {
// this category belongs in default profile
if(topic.getDefaultId() == null && children != null) {
onDeleteDefaultCategory(categoryId, topicId, children);
}
// for(String subCategoryId : category.getSubCategories()) {
// SubCategory<String> subcategory = subCategoryDAO.findById(subCategoryId);
// if(subcategory == null) {
// // EXCEPTION - SubCategory not found
// throw new EntityNotFoundException("Delete category: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")");
// }
//
// for(String chartSectionId : subcategory.getCharts()) {
// Section<String> chartSection = sectionDAO.findById(chartSectionId);
// if (chartSection == null) {
// // EXCEPTION - Section not found
// throw new EntityNotFoundException("Delete topic: 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 topic: 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);
// }
//
// subCategoryDAO.delete(subCategoryId);
// }
subCategoryController.deleteTree(category);
category.setSubCategories(null);
categories.remove(index);
topicDAO.save(topic);
categoryDAO.delete(categoryId);
log.debug("Category deleted!");
} else {
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
throw new PathNotValidException("Delete category: Category with id: "+categoryId+" not found in Topic: "+topicId);
}
} else {
// EXCEPTION - Category not found
throw new EntityNotFoundException("Delete category: Category with id: "+categoryId+" not found");
}
} else {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
throw new PathNotValidException("Delete category: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
}
} else {
// EXCEPTION - Topic not found
throw new EntityNotFoundException("Delete category: Topic with id: "+topicId+" not found");
}
} else {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("Delete category: Stakeholder with id: "+stakeholderId+" not found");
}
return true;
}
public boolean onDeleteDefaultCategory(String defaultCategoryId, String defaultTopicId, String children) {
if(children.equals("delete")) {
List<Topic> topics = topicDAO.findByDefaultId(defaultTopicId);
List<Category> categories = categoryDAO.findByDefaultId(defaultCategoryId);
for(Topic topic : topics) {
Iterator<Category> categoriesIterator = categories.iterator();
while(categoriesIterator.hasNext()) {
Category category = categoriesIterator.next();
String categoryId = category.getId();
if(topic.getCategories() != null && topic.getCategories().contains(categoryId)) {
categoriesIterator.remove();
topic.getCategories().remove(categoryId);
topicDAO.save(topic);
subCategoryController.deleteTree(category);
categoryDAO.delete(categoryId);
log.debug("Category with id: "+categoryId+" deleted!");
break;
}
}
}
} else if(children.equals("disconnect")) {
List<Category> categories = categoryDAO.findByDefaultId(defaultCategoryId);
for(Category category : categories) {
subCategoryController.disConnectTree(category);
category.setDefaultId(null);
categoryDAO.save(category);
log.debug("DefaultId for Category with id: "+category.getId()+" empty!");
}
}
return true;
}
@PreAuthorize("isAuthenticated()")
@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);
[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> oldCategories = topic.getCategories();
for (String categoryId : oldCategories) {
if (!categories.contains(categoryId)) {
categories.add(categoryId);
}
}
topic.setCategories(categories);
List<Category> categoriesFull = new ArrayList<>();
for(String categoryId : categories) {
[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
Category category = categoryDAO.findById(categoryId);
if(category == null) {
// EXCEPTION - Category not found
throw new EntityNotFoundException("Reorder Categories: Category with id: " + categoryId + " not found");
}
categoriesFull.add(category);
}
[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
topicDAO.save(topic);
log.debug("Categories reordered!");
return categoriesFull;
}
// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/toggle-status", method = RequestMethod.POST)
// public Boolean toggleCategoryStatus(@PathVariable("stakeholderId") String stakeholderId,
// @PathVariable("topicId") String topicId,
// @PathVariable("categoryId") String categoryId) {
// log.debug("toggle category status (isActive)");
// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
//
// Category category = categoryDAO.findById(categoryId);
// if (category == null) {
// // EXCEPTION - Category not found
// throw new EntityNotFoundException("Toggle category status: Category with id: "+categoryId+" not found");
// }
// category.setIsActive(!category.getIsActive());
//
// this.toggleCategory(stakeholderId, topicId, category);
//
// return category.getIsActive();
// }
//
// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/toggle-access", method = RequestMethod.POST)
// public Boolean toggleCategoryAccess(@PathVariable("stakeholderId") String stakeholderId,
// @PathVariable("topicId") String topicId,
// @PathVariable("categoryId") String categoryId) {
// log.debug("toggle category access (isPublic)");
// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
//
// Category category = categoryDAO.findById(categoryId);
// if (category == null) {
// // EXCEPTION - Category not found
// throw new EntityNotFoundException("Toggle category access: Category with id: "+categoryId+" not found");
// }
// category.setIsPublic(!category.getIsPublic());
//
// this.toggleCategory(stakeholderId, topicId, category);
//
// return category.getIsPublic();
// }
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/change-visibility", method = RequestMethod.POST)
public Category changeCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) {
log.debug("change category visibility: "+visibility + " - toggle propagate: "+((propagate != null && propagate) ? "true" : "false"));
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if (stakeholder != null) {
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("Toggle category: You are not authorized to update stakeholder with id: "+stakeholderId);
}
Topic<String> topic = topicDAO.findById(topicId);
if (topic != null) {
if (stakeholder.getTopics().contains(topicId)) {
if (topic.getCategories().contains(categoryId)) {
return changeVisibilityTree(categoryId, visibility, propagate);
} else {
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
throw new PathNotValidException("Toggle category: Category with id: "+categoryId+" not found in Topic: "+topicId);
}
} else {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
throw new PathNotValidException("Toggle category: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
}
} else {
// EXCEPTION - Topic not found
throw new EntityNotFoundException("Toggle category: Topic with id: "+topicId+" not found");
}
} else {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("Toggle category: Stakeholder with id: "+stakeholderId+" not found");
}
}
public Category changeVisibilityTree(String categoryId, Visibility visibility, Boolean propagate) {
Category<String> category = categoryDAO.findById(categoryId);
if (category == null) {
// EXCEPTION - Category not found
throw new EntityNotFoundException("Change category visibility: Category with id: "+categoryId+" not found");
}
Category<SubCategory> categoryFull = new Category(category);
List<SubCategory> subCategoriesFull = new ArrayList<>();
if(propagate != null && propagate) {
for (String subCategoryId : category.getSubCategories()) {
subCategoriesFull.add(subCategoryController.changeVisibilityTree(subCategoryId, visibility, propagate));
}
}
category.setVisibility(visibility);
categoryDAO.save(category);
log.debug("Category toggled!");
categoryFull.setVisibility(visibility);
categoryFull.setSubCategories(subCategoriesFull);
return categoryFull;
}
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");
}
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 category: 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("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) {
Category category = categoryDAO.findById(categoryId);
if (category == null) {
// EXCEPTION - Category not found
throw new EntityNotFoundException("Category delete tree: Category with id: "+categoryId+" not found (category exists in topic: "+topic.getId()+")");
}
subCategoryController.deleteTree(category);
categoryDAO.delete(categoryId);
}
}
public void disConnectTree(Topic topic) {
List<String> categories = topic.getCategories();
for(String categoryId : categories) {
Category category = categoryDAO.findById(categoryId);
if (category == null) {
// EXCEPTION - Category not found
throw new EntityNotFoundException("Category disconnect tree: Category with id: "+categoryId+" not found (category exists in topic: "+topic.getId()+")");
}
subCategoryController.disConnectTree(category);
category.setDefaultId(null);
categoryDAO.save(category);
}
}
}