2019-11-04 10:03:49 +01:00
|
|
|
package eu.dnetlib.uoamonitorservice.controllers;
|
|
|
|
|
2024-03-12 23:20:55 +01:00
|
|
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
[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;
|
2024-03-08 19:55:51 +01:00
|
|
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
|
|
|
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
2024-03-12 23:20:55 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
|
2024-03-08 19:55:51 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
2024-03-12 23:20:55 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
2024-02-20 08:10:41 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
|
2024-03-12 23:20:55 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.service.TopicService;
|
2022-10-10 14:27:17 +02:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2019-11-04 10:03:49 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2020-11-11 13:45:59 +01:00
|
|
|
import org.springframework.security.access.AccessDeniedException;
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
2019-11-04 10:03:49 +01:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
2024-03-08 19:55:51 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
2019-11-04 10:03:49 +01:00
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin(origins = "*")
|
|
|
|
public class StakeholderController {
|
2022-10-10 14:27:17 +02:00
|
|
|
private final Logger log = LogManager.getLogger(this.getClass());
|
2019-11-04 10:03:49 +01:00
|
|
|
|
2024-03-12 23:20:55 +01:00
|
|
|
private final PortalService portalService;
|
|
|
|
private final StakeholderService stakeholderService;
|
2024-02-20 08:10:41 +01:00
|
|
|
|
2019-11-04 10:03:49 +01:00
|
|
|
@Autowired
|
2024-03-08 19:55:51 +01:00
|
|
|
public StakeholderController(PortalService portalService, StakeholderService stakeholderService) {
|
|
|
|
this.portalService = portalService;
|
|
|
|
this.stakeholderService = stakeholderService;
|
|
|
|
}
|
2022-07-27 13:51:56 +02:00
|
|
|
|
[Trunk | Monitor Service]:
1. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java && SectionController.java && IndicatorController.java:
a. Comment logs for get requests.
b. Use "ForbiddenException" instead of "AccessDeniedException"
c. On /save, if full entity has id (already in DB), if not found in DB throw EntityNotFoundException.
d. Get children (e.g. when saving a Topic, get its categories) from DB.
2. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java:
In /reorder, if there are in DB, ids that are missing from reordered list, do reordering and add in the end of list the missing ids.
3. ReorderEvent.java: [NEW] Added class ReorderEvent with fields "action" (String), "target" (String), "ids" (List<String>) (used in IndicatorController.java).
4. IndicatorController.java:
a. In /reorder, @RequestBody changed from List<String> indicators to ReorderEvent reorderEvent.
b. If there are in DB, ids that are missing from reordered list AND missing id is not moved to other section (action = removed and target = missing id), do reordering and add in the end of list the missing ids.
5. ExceptionsHandler.java: exception handler methods "invalidInput()", "nullPointerException()", "notFoundException()" moved to "Admin Tools Library" - "accessDeniedException()" is removed.
6. responses/ExceptionResponse.java: File and folder deleted (moved to "Admin Tools Library").
7. RolesUtils.java: Added method "isLoggedIn()" (checks if no roles for user, or user has role "ROLE_ANONYMOUS").
2020-12-09 15:24:27 +01:00
|
|
|
@PreAuthorize("isAuthenticated()")
|
|
|
|
@RequestMapping(value = "/stakeholder/alias", method = RequestMethod.GET)
|
|
|
|
public List<String> getAllReservedStakeholderAlias() {
|
2024-03-05 17:51:14 +01:00
|
|
|
List<String> stakeholderAlias = this.stakeholderService.getAllAliases();
|
|
|
|
stakeholderAlias.add("all");
|
[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
|
|
|
stakeholderAlias.add("default");
|
|
|
|
stakeholderAlias.add("alias");
|
|
|
|
return stakeholderAlias;
|
|
|
|
}
|
|
|
|
|
2024-03-12 23:20:55 +01:00
|
|
|
@PreAuthorize("hasAnyAuthority(" +
|
2024-03-08 19:55:51 +01:00
|
|
|
"@AuthorizationService.PORTAL_ADMIN, " +
|
2024-03-12 23:20:55 +01:00
|
|
|
"@AuthorizationService.curator(#stakeholder.getType()))")
|
2019-11-22 16:50:59 +01:00
|
|
|
@RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
|
2024-04-02 13:49:02 +02:00
|
|
|
public StakeholderFull buildStakeholder(@RequestBody StakeholderFull stakeholder) {
|
2019-11-22 16:50:59 +01:00
|
|
|
log.debug("build stakeholder");
|
2024-03-12 23:20:55 +01:00
|
|
|
log.debug("Alias: " + stakeholder.getAlias());
|
|
|
|
Portal portal = portalService.getPortal(stakeholder.getAlias());
|
2024-03-08 19:55:51 +01:00
|
|
|
if (portal == null) {
|
2022-07-27 13:51:56 +02:00
|
|
|
portal = new Portal();
|
2024-03-12 23:20:55 +01:00
|
|
|
portal.setPid(stakeholder.getAlias());
|
|
|
|
portal.setName(stakeholder.getName());
|
|
|
|
portal.setType(stakeholder.getType());
|
2022-07-27 13:51:56 +02:00
|
|
|
portalService.insertPortal(portal);
|
|
|
|
}
|
2024-04-02 13:49:02 +02:00
|
|
|
return this.stakeholderService.buildStakeholder(stakeholder);
|
2024-03-12 23:20:55 +01:00
|
|
|
}
|
2020-11-11 13:45:59 +01:00
|
|
|
|
2024-03-08 19:55:51 +01:00
|
|
|
@PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN)")
|
2019-11-04 10:03:49 +01:00
|
|
|
@RequestMapping(value = "/stakeholder/all", method = RequestMethod.GET)
|
|
|
|
public List<Stakeholder> getAllStakeholders(@RequestParam(required = false) String type) {
|
2024-03-08 19:55:51 +01:00
|
|
|
return this.stakeholderService.getAll(type);
|
2019-11-04 10:03:49 +01:00
|
|
|
}
|
|
|
|
|
2020-11-11 13:45:59 +01:00
|
|
|
@PreAuthorize("isAuthenticated()")
|
2019-11-04 10:03:49 +01:00
|
|
|
@RequestMapping(value = "/stakeholder/default", method = RequestMethod.GET)
|
2024-03-08 19:55:51 +01:00
|
|
|
public List<StakeholderFull> getAllDefaultStakeholders(@RequestParam(required = false) String type) {
|
|
|
|
return this.stakeholderService.getAllDefaultByRole(type).stream()
|
2024-03-12 23:20:55 +01:00
|
|
|
.map(this.stakeholderService::getFullStakeholder)
|
2024-03-08 19:55:51 +01:00
|
|
|
.collect(Collectors.toList());
|
2019-11-04 10:03:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/stakeholder", method = RequestMethod.GET)
|
2024-03-27 13:07:41 +01:00
|
|
|
public List<Stakeholder> getVisibleStakeholders(@RequestParam(required = false) String type,
|
2021-02-24 20:22:19 +01:00
|
|
|
@RequestParam(required = false) String defaultId) {
|
2024-02-20 08:10:41 +01:00
|
|
|
return stakeholderService.getStakeholdersByTypeAndRole(type, defaultId, false);
|
2020-11-11 13:45:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@PreAuthorize("isAuthenticated()")
|
|
|
|
@RequestMapping(value = "/my-stakeholder", method = RequestMethod.GET)
|
2024-03-27 13:07:41 +01:00
|
|
|
public List<Stakeholder> getManagedStakeholders(@RequestParam(required = false) String type) {
|
2024-02-20 08:10:41 +01:00
|
|
|
return stakeholderService.getStakeholdersByTypeAndRole(type, null, true);
|
2019-11-04 10:03:49 +01:00
|
|
|
}
|
|
|
|
|
2024-02-20 08:10:41 +01:00
|
|
|
@RequestMapping(value = "/stakeholder/{alias:.+}", method = RequestMethod.GET)
|
2024-03-08 19:55:51 +01:00
|
|
|
public StakeholderFull getStakeholder(@PathVariable("alias") String alias) {
|
|
|
|
StakeholderFull stakeholder = this.stakeholderService.getFullStakeholder(this.stakeholderService.findByAlias(alias));
|
|
|
|
if (stakeholder == null) {
|
|
|
|
throw new ForbiddenException("Get stakeholder: You are not authorized to access stakeholder with alias: " + alias);
|
2020-11-11 13:45:59 +01:00
|
|
|
}
|
2024-03-08 19:55:51 +01:00
|
|
|
return stakeholder;
|
1. Stakeholder.java: Create constructor and copy constructor & change getters-setters for 'isDeafult', 'isPublic' and 'isActive' fields.
2. Topic.java: Create constructor and copy constructor & change getters-setters for 'isPublic' and 'isActive' fields.
3. Category.java: Create constructor and copy constructor & change getters-setters for 'isOverview, 'isPublic' and 'isActive' fields & remove field 'description'.
4. SubCategory.java: Create constructor and copy constructor & change getters-setters for 'isPublic' and 'isActive' fields & remove field 'description' &
make charts and numbers (List) generic (String or Indicator).
5. Indicator.java: Change getters-setters for 'indicatorPaths', 'isPublic' and 'isActive' fields & create method: public boolean hasType(String str), to check if "chart" or "number".
6. IndicatorPath.java: Add fields in schema (chartObject, parameters, filters) & add in enum IndicatorPathType types: pie, line, image.
7. MongoDBStakeholderDAO.java & StakeholderDAO.java: Add method: Stakeholder findByAlias(String Alias)
8. StakeholderController.java:
a. Add method: public Stakeholder setIndicatorsForStakeholder(Stakeholder stakeholder) to replace indicator ids with Indicator objects
(used by: getAllStakeholders, getAllDefaultStakeholders, getAllRealStakeholders, getStakeholder (by alias))
b. Add method: public Stakeholder getStakeholder(@PathVariable("alias") String alias) - /stakeholder/{alias}
c. Add method: public Stakeholder saveStakeholder(@RequestBody Stakeholder stakeholder) - /stakeholder/save
d. Add method: public boolean deleteIndicator(...) - /{stakeholder}/{topic}/{category}/{subcategory}/indicator/{id}
e. Add method: public Indicator saveIndicator(...) - /{stakeholder}/{topic}/{category}/{subcategory}/indicator/save (in body send Indicator object)
2019-11-11 17:38:36 +01:00
|
|
|
}
|
|
|
|
|
2024-03-12 23:20:55 +01:00
|
|
|
@PreAuthorize("hasAnyAuthority("
|
2024-03-08 19:55:51 +01:00
|
|
|
+ "@AuthorizationService.PORTAL_ADMIN, "
|
2024-03-12 23:20:55 +01:00
|
|
|
+ "@AuthorizationService.curator(#stakeholder.getType()), "
|
|
|
|
+ "@AuthorizationService.manager(#stakeholder.getType(), #stakeholder.getAlias()) "
|
2024-03-08 19:55:51 +01:00
|
|
|
+ ")")
|
2019-11-22 16:50:59 +01:00
|
|
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
2024-03-12 23:20:55 +01:00
|
|
|
public StakeholderFull saveStakeholder(@RequestBody StakeholderFull stakeholder) {
|
1. Stakeholder.java: Create constructor and copy constructor & change getters-setters for 'isDeafult', 'isPublic' and 'isActive' fields.
2. Topic.java: Create constructor and copy constructor & change getters-setters for 'isPublic' and 'isActive' fields.
3. Category.java: Create constructor and copy constructor & change getters-setters for 'isOverview, 'isPublic' and 'isActive' fields & remove field 'description'.
4. SubCategory.java: Create constructor and copy constructor & change getters-setters for 'isPublic' and 'isActive' fields & remove field 'description' &
make charts and numbers (List) generic (String or Indicator).
5. Indicator.java: Change getters-setters for 'indicatorPaths', 'isPublic' and 'isActive' fields & create method: public boolean hasType(String str), to check if "chart" or "number".
6. IndicatorPath.java: Add fields in schema (chartObject, parameters, filters) & add in enum IndicatorPathType types: pie, line, image.
7. MongoDBStakeholderDAO.java & StakeholderDAO.java: Add method: Stakeholder findByAlias(String Alias)
8. StakeholderController.java:
a. Add method: public Stakeholder setIndicatorsForStakeholder(Stakeholder stakeholder) to replace indicator ids with Indicator objects
(used by: getAllStakeholders, getAllDefaultStakeholders, getAllRealStakeholders, getStakeholder (by alias))
b. Add method: public Stakeholder getStakeholder(@PathVariable("alias") String alias) - /stakeholder/{alias}
c. Add method: public Stakeholder saveStakeholder(@RequestBody Stakeholder stakeholder) - /stakeholder/save
d. Add method: public boolean deleteIndicator(...) - /{stakeholder}/{topic}/{category}/{subcategory}/indicator/{id}
e. Add method: public Indicator saveIndicator(...) - /{stakeholder}/{topic}/{category}/{subcategory}/indicator/save (in body send Indicator object)
2019-11-11 17:38:36 +01:00
|
|
|
log.debug("save stakeholder");
|
2024-03-08 19:55:51 +01:00
|
|
|
log.debug("Alias: " + stakeholder.getAlias() + " - Id: " + stakeholder.getId());
|
2024-04-02 13:49:02 +02:00
|
|
|
return this.stakeholderService.getFullStakeholder(this.stakeholderService.save(new Stakeholder(stakeholder)));
|
2024-03-12 23:20:55 +01:00
|
|
|
}
|
2019-11-19 14:05:43 +01:00
|
|
|
|
2024-03-12 23:20:55 +01:00
|
|
|
@PreAuthorize("isAuthenticated()")
|
2019-11-22 16:50:59 +01:00
|
|
|
@RequestMapping(value = "/{stakeholderId}/delete", method = RequestMethod.DELETE)
|
2024-03-12 23:20:55 +01:00
|
|
|
public boolean deleteStakeholder(@PathVariable("stakeholderId") String id) {
|
2019-11-22 16:50:59 +01:00
|
|
|
log.debug("delete stakeholder");
|
2024-03-12 23:20:55 +01:00
|
|
|
log.debug("Id: " + id);
|
|
|
|
Portal portal = portalService.getPortal(this.stakeholderService.delete(id));
|
|
|
|
if (portal != null) {
|
|
|
|
portalService.deletePortal(portal.getId());
|
1. Stakeholder.java: Create constructor and copy constructor & change getters-setters for 'isDeafult', 'isPublic' and 'isActive' fields.
2. Topic.java: Create constructor and copy constructor & change getters-setters for 'isPublic' and 'isActive' fields.
3. Category.java: Create constructor and copy constructor & change getters-setters for 'isOverview, 'isPublic' and 'isActive' fields & remove field 'description'.
4. SubCategory.java: Create constructor and copy constructor & change getters-setters for 'isPublic' and 'isActive' fields & remove field 'description' &
make charts and numbers (List) generic (String or Indicator).
5. Indicator.java: Change getters-setters for 'indicatorPaths', 'isPublic' and 'isActive' fields & create method: public boolean hasType(String str), to check if "chart" or "number".
6. IndicatorPath.java: Add fields in schema (chartObject, parameters, filters) & add in enum IndicatorPathType types: pie, line, image.
7. MongoDBStakeholderDAO.java & StakeholderDAO.java: Add method: Stakeholder findByAlias(String Alias)
8. StakeholderController.java:
a. Add method: public Stakeholder setIndicatorsForStakeholder(Stakeholder stakeholder) to replace indicator ids with Indicator objects
(used by: getAllStakeholders, getAllDefaultStakeholders, getAllRealStakeholders, getStakeholder (by alias))
b. Add method: public Stakeholder getStakeholder(@PathVariable("alias") String alias) - /stakeholder/{alias}
c. Add method: public Stakeholder saveStakeholder(@RequestBody Stakeholder stakeholder) - /stakeholder/save
d. Add method: public boolean deleteIndicator(...) - /{stakeholder}/{topic}/{category}/{subcategory}/indicator/{id}
e. Add method: public Indicator saveIndicator(...) - /{stakeholder}/{topic}/{category}/{subcategory}/indicator/save (in body send Indicator object)
2019-11-11 17:38:36 +01:00
|
|
|
}
|
|
|
|
return true;
|
2024-03-12 23:20:55 +01:00
|
|
|
}
|
1. Stakeholder.java: Create constructor and copy constructor & change getters-setters for 'isDeafult', 'isPublic' and 'isActive' fields.
2. Topic.java: Create constructor and copy constructor & change getters-setters for 'isPublic' and 'isActive' fields.
3. Category.java: Create constructor and copy constructor & change getters-setters for 'isOverview, 'isPublic' and 'isActive' fields & remove field 'description'.
4. SubCategory.java: Create constructor and copy constructor & change getters-setters for 'isPublic' and 'isActive' fields & remove field 'description' &
make charts and numbers (List) generic (String or Indicator).
5. Indicator.java: Change getters-setters for 'indicatorPaths', 'isPublic' and 'isActive' fields & create method: public boolean hasType(String str), to check if "chart" or "number".
6. IndicatorPath.java: Add fields in schema (chartObject, parameters, filters) & add in enum IndicatorPathType types: pie, line, image.
7. MongoDBStakeholderDAO.java & StakeholderDAO.java: Add method: Stakeholder findByAlias(String Alias)
8. StakeholderController.java:
a. Add method: public Stakeholder setIndicatorsForStakeholder(Stakeholder stakeholder) to replace indicator ids with Indicator objects
(used by: getAllStakeholders, getAllDefaultStakeholders, getAllRealStakeholders, getStakeholder (by alias))
b. Add method: public Stakeholder getStakeholder(@PathVariable("alias") String alias) - /stakeholder/{alias}
c. Add method: public Stakeholder saveStakeholder(@RequestBody Stakeholder stakeholder) - /stakeholder/save
d. Add method: public boolean deleteIndicator(...) - /{stakeholder}/{topic}/{category}/{subcategory}/indicator/{id}
e. Add method: public Indicator saveIndicator(...) - /{stakeholder}/{topic}/{category}/{subcategory}/indicator/save (in body send Indicator object)
2019-11-11 17:38:36 +01:00
|
|
|
|
2024-03-12 23:20:55 +01:00
|
|
|
@PreAuthorize("isAuthenticated()")
|
2020-11-11 13:45:59 +01:00
|
|
|
@RequestMapping(value = "/{stakeholderId}/change-visibility", method = RequestMethod.POST)
|
2024-03-12 23:20:55 +01:00
|
|
|
public StakeholderFull changeStakeholderVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
|
|
|
@RequestParam("visibility") Visibility visibility, @RequestParam(defaultValue = "false") Boolean propagate) {
|
2024-03-21 11:42:34 +01:00
|
|
|
log.debug("change stakeholder visibility: " + visibility + " - toggle propagate: " + propagate);
|
2024-03-08 19:55:51 +01:00
|
|
|
log.debug("Stakeholder: " + stakeholderId);
|
2024-03-21 11:42:34 +01:00
|
|
|
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
|
|
|
return this.stakeholderService.changeVisibility(stakeholder, visibility, propagate);
|
2022-09-14 17:02:47 +02:00
|
|
|
}
|
2019-11-04 10:03:49 +01:00
|
|
|
}
|