diff --git a/pom.xml b/pom.xml index b80a9d8..e01438d 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,7 @@ eu.dnetlib uoa-admin-tools-library - 1.0.4 + 1.0.5 eu.dnetlib diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java index 25451ab..b5e6ddc 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java @@ -1,6 +1,9 @@ package eu.dnetlib.uoamonitorservice.controllers; +import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; +import eu.dnetlib.uoaadmintoolslibrary.entities.PortalType; import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; +import eu.dnetlib.uoaadmintoolslibrary.services.PortalService; import eu.dnetlib.uoamonitorservice.dao.*; import eu.dnetlib.uoamonitorservice.entities.*; import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; @@ -13,10 +16,7 @@ import org.springframework.security.access.AuthorizationServiceException; 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; +import java.util.*; @RestController @CrossOrigin(origins = "*") @@ -47,6 +47,9 @@ public class StakeholderController { @Autowired private TopicController topicController; + @Autowired + private PortalService portalService; + @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/stakeholder/alias", method = RequestMethod.GET) public List getAllReservedStakeholderAlias() { @@ -96,6 +99,16 @@ public class StakeholderController { Stakeholder stakeholderSaved = stakeholderDAO.save(stakeholder); stakeholderFull.setId(stakeholderSaved.getId()); + + Portal portal = portalService.getPortal(stakeholderFull.getAlias()); + if(portal == null) { + portal = new Portal(); + portal.setPid(stakeholderFull.getAlias()); + portal.setName(stakeholderFull.getName()); + portal.setType(stakeholderFull.getType()); + portalService.insertPortal(portal); + } + return stakeholderFull; //return null; } @@ -548,8 +561,10 @@ public class StakeholderController { log.debug("Id: "+stakeholderId); Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); + String pid = null; if(stakeholder != null) { + pid = stakeholder.getAlias(); // List roles = authorizationService.getRoles(); List roles = rolesUtils.getRoles(); @@ -623,6 +638,11 @@ public class StakeholderController { stakeholder.setTopics(null); stakeholderDAO.delete(stakeholderId); log.debug("Stakeholder deleted!"); + + Portal portal = portalService.getPortal(pid); + if(portal != null) { + portalService.deletePortal(portal.getId()); + } } else { // EXCEPTION - Stakeholder not found throw new EntityNotFoundException("Delete stakeholder: Stakeholder with id: "+stakeholderId+" not found");