From 6484343d2f7bca5bc0e2ea0b1f281dc73e44de3b Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Thu, 25 Feb 2021 19:00:05 +0000 Subject: [PATCH] [Admin Tools | Trunk]: Add get managers method. Delete no needed files. --- pom.xml | 11 +- .../UoaAdminToolsApplication.java | 19 +- .../UoaAdminToolsConfiguration.java | 37 --- .../properties/ManagersApiConfig.java | 26 ++ .../properties/SecurityConfig.java | 40 --- .../controllers/CommunityController.java | 15 +- .../controllers/ConnectController.java | 25 +- .../controllers/CuratorController.java | 61 ++--- .../controllers/EmailController.java | 2 +- .../controllers/ExploreController.java | 6 +- .../controllers/NotificationsController.java | 5 +- .../PortalSubscribersController.java | 12 +- .../uoaadmintools/entities/Manager.java | 44 +++ .../entities/curator/Response.java | 18 ++ .../handlers/AuthorizationHandler.java | 71 ----- .../handlers/CommunityNotFoundException.java | 15 -- .../uoaadmintools/handlers/ErrorDetails.java | 17 -- .../handlers/ExceptionsHandler.java | 54 ---- .../handlers/utils/AuthorizationUtils.java | 253 ------------------ .../handlers/utils/CommunityInfo.java | 81 ------ .../handlers/utils/UserInfo.java | 46 ---- .../services/CuratorService.java | 57 ++++ .../services/ManagerService.java | 31 +++ src/main/resources/admintools.properties | 22 +- 24 files changed, 254 insertions(+), 714 deletions(-) delete mode 100644 src/main/java/eu/dnetlib/uoaadmintools/UoaAdminToolsConfiguration.java create mode 100644 src/main/java/eu/dnetlib/uoaadmintools/configuration/properties/ManagersApiConfig.java delete mode 100644 src/main/java/eu/dnetlib/uoaadmintools/configuration/properties/SecurityConfig.java create mode 100644 src/main/java/eu/dnetlib/uoaadmintools/entities/Manager.java create mode 100644 src/main/java/eu/dnetlib/uoaadmintools/entities/curator/Response.java delete mode 100644 src/main/java/eu/dnetlib/uoaadmintools/handlers/AuthorizationHandler.java delete mode 100644 src/main/java/eu/dnetlib/uoaadmintools/handlers/CommunityNotFoundException.java delete mode 100644 src/main/java/eu/dnetlib/uoaadmintools/handlers/ErrorDetails.java delete mode 100644 src/main/java/eu/dnetlib/uoaadmintools/handlers/ExceptionsHandler.java delete mode 100644 src/main/java/eu/dnetlib/uoaadmintools/handlers/utils/AuthorizationUtils.java delete mode 100644 src/main/java/eu/dnetlib/uoaadmintools/handlers/utils/CommunityInfo.java delete mode 100644 src/main/java/eu/dnetlib/uoaadmintools/handlers/utils/UserInfo.java create mode 100644 src/main/java/eu/dnetlib/uoaadmintools/services/CuratorService.java create mode 100644 src/main/java/eu/dnetlib/uoaadmintools/services/ManagerService.java diff --git a/pom.xml b/pom.xml index c6a1c6d..f1313a6 100644 --- a/pom.xml +++ b/pom.xml @@ -80,12 +80,11 @@ uoa-admin-tools-library 1.0.0-SNAPSHOT - - - - - - + + eu.dnetlib + uoa-authorization-library + 1.0.0-SNAPSHOT + diff --git a/src/main/java/eu/dnetlib/uoaadmintools/UoaAdminToolsApplication.java b/src/main/java/eu/dnetlib/uoaadmintools/UoaAdminToolsApplication.java index 97d4f98..e199d70 100644 --- a/src/main/java/eu/dnetlib/uoaadmintools/UoaAdminToolsApplication.java +++ b/src/main/java/eu/dnetlib/uoaadmintools/UoaAdminToolsApplication.java @@ -1,5 +1,7 @@ package eu.dnetlib.uoaadmintools; +import com.fasterxml.jackson.databind.ObjectMapper; +import eu.dnetlib.uoaadmintools.configuration.properties.ManagersApiConfig; import eu.dnetlib.uoaadmintools.configuration.properties.MongoConfig; //import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig; //import eu.dnetlib.uoaauthorizationlibrary.configuration.AuthorizationConfiguration; @@ -7,21 +9,32 @@ import eu.dnetlib.uoaauthorizationlibrary.configuration.AuthorizationConfigurati import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySources; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.client.RestTemplate; -@SpringBootApplication(scanBasePackages = {"eu.dnetlib.uoaadmintools", "eu.dnetlib.uoaadmintoolslibrary"}) +@SpringBootApplication(scanBasePackages = {"eu.dnetlib.uoaadmintools", "eu.dnetlib.uoaadmintoolslibrary", "eu.dnetlib.uoanotificationservice"}) @PropertySources({ @PropertySource("classpath:admintools.properties"), @PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true) }) -//SecurityConfig.class, -@EnableConfigurationProperties({MongoConfig.class}) +@EnableConfigurationProperties({MongoConfig.class, ManagersApiConfig.class}) @Import(AuthorizationConfiguration.class) public class UoaAdminToolsApplication { public static void main(String[] args) { SpringApplication.run(UoaAdminToolsApplication.class, args); } + + @Bean + RestTemplate restTemplate() { + RestTemplate restTemplate = new RestTemplate(); + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); + converter.setObjectMapper(new ObjectMapper()); + restTemplate.getMessageConverters().add(converter); + return restTemplate; + } } diff --git a/src/main/java/eu/dnetlib/uoaadmintools/UoaAdminToolsConfiguration.java b/src/main/java/eu/dnetlib/uoaadmintools/UoaAdminToolsConfiguration.java deleted file mode 100644 index 88625ca..0000000 --- a/src/main/java/eu/dnetlib/uoaadmintools/UoaAdminToolsConfiguration.java +++ /dev/null @@ -1,37 +0,0 @@ -package eu.dnetlib.uoaadmintools; - -//import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig; -//import eu.dnetlib.uoaadmintools.handlers.AuthorizationHandler; -import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; - -/** - * Created by argirok on 23/2/2018. - */ - -@Configuration -public class UoaAdminToolsConfiguration extends WebMvcConfigurerAdapter { - private final Logger log = Logger.getLogger(this.getClass()); - -// @Autowired -// private SecurityConfig securityConfig; - - - @Bean - public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { - return new PropertySourcesPlaceholderConfigurer(); - } - -// @Override -// public void addInterceptors(InterceptorRegistry registry) { -// registry.addInterceptor(new AuthorizationHandler(securityConfig.getUserInfoUrl(), securityConfig.getOriginServer(), securityConfig.getPostsAllowed())) -// .addPathPatterns("/**"); -// -// } - -} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/configuration/properties/ManagersApiConfig.java b/src/main/java/eu/dnetlib/uoaadmintools/configuration/properties/ManagersApiConfig.java new file mode 100644 index 0000000..b15f10a --- /dev/null +++ b/src/main/java/eu/dnetlib/uoaadmintools/configuration/properties/ManagersApiConfig.java @@ -0,0 +1,26 @@ +package eu.dnetlib.uoaadmintools.configuration.properties; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("admintool.managers.api") +public class ManagersApiConfig { + + private String id; + private String email; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/configuration/properties/SecurityConfig.java b/src/main/java/eu/dnetlib/uoaadmintools/configuration/properties/SecurityConfig.java deleted file mode 100644 index 3a43183..0000000 --- a/src/main/java/eu/dnetlib/uoaadmintools/configuration/properties/SecurityConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -//package eu.dnetlib.uoaadmintools.configuration.properties; -// -//import org.springframework.boot.context.properties.ConfigurationProperties; -// -//import java.util.ArrayList; -//import java.util.List; -// -//@ConfigurationProperties("admintool.security") -//public class SecurityConfig { -// -// private String userInfoUrl; -// private String originServer; -// private List postsAllowed = new ArrayList<>(); -// -// public void setUserInfoUrl(String userInfoUrl) { -// this.userInfoUrl = userInfoUrl; -// } -// -// public void setOriginServer(String originServer) { -// this.originServer = originServer; -// } -// -// -// public void setPostsAllowed(List posts) { -// this.postsAllowed = posts; -// } -// -// public String getUserInfoUrl() { -// return userInfoUrl; -// } -// -// public String getOriginServer() { -// return originServer; -// } -// -// public List getPostsAllowed() { -// return postsAllowed; -// } -// -//} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunityController.java b/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunityController.java index 7de2053..d66450b 100644 --- a/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunityController.java +++ b/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunityController.java @@ -6,18 +6,17 @@ import eu.dnetlib.uoaadmintools.services.NotificationsService; import eu.dnetlib.uoaadmintools.services.StatisticsService; import eu.dnetlib.uoaadmintools.services.SubscriberService; import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; -import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*; +import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse; import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; -import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException; import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException; -import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; import eu.dnetlib.uoaadmintoolslibrary.services.PortalService; +import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService; import org.apache.log4j.Logger; -import org.springframework.web.bind.annotation.*; import org.springframework.beans.factory.annotation.Autowired; - -import java.util.*; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.List; @RestController @RequestMapping("/community") @@ -26,7 +25,7 @@ public class CommunityController { private final Logger log = Logger.getLogger(this.getClass()); @Autowired - private RolesUtils rolesUtils; + private AuthorizationService authorizationService; @Autowired private LayoutService layoutService; @@ -96,7 +95,7 @@ public class CommunityController { @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") @RequestMapping(value = "/delete", method = RequestMethod.POST) public Boolean deleteCommunities(@RequestBody List portals) { - List roles = rolesUtils.getRoles(); + List roles = authorizationService.getRoles(); for (String id: portals) { Portal portal = portalService.getPortalById(id); diff --git a/src/main/java/eu/dnetlib/uoaadmintools/controllers/ConnectController.java b/src/main/java/eu/dnetlib/uoaadmintools/controllers/ConnectController.java index e9909b7..044aef5 100644 --- a/src/main/java/eu/dnetlib/uoaadmintools/controllers/ConnectController.java +++ b/src/main/java/eu/dnetlib/uoaadmintools/controllers/ConnectController.java @@ -1,18 +1,17 @@ package eu.dnetlib.uoaadmintools.controllers; -import eu.dnetlib.uoaadmintools.entities.Layout; import eu.dnetlib.uoaadmintools.services.LayoutService; import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; -import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*; +import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse; import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException; import eu.dnetlib.uoaadmintoolslibrary.services.PortalService; import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; -import org.springframework.beans.factory.annotation.Autowired; -import java.util.*; +import java.util.List; @RestController @RequestMapping("/connect") @@ -29,16 +28,16 @@ public class ConnectController { @RequestMapping(value = "/update", method = RequestMethod.POST) public PortalResponse updateConnect(@RequestBody Portal portal) { - if(!portal.getType().equals("connect")) { + if (!portal.getType().equals("connect")) { // EXCEPTION - MismatchingContent - throw new MismatchingContentException("Update Connect: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of connect"); + throw new MismatchingContentException("Update Connect: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of connect"); } PortalResponse portalResponse = portalService.updatePortal(portal); String old_pid = portalResponse.getPid(); String new_pid = portal.getPid(); - if(!old_pid.equals(new_pid)) { + if (!old_pid.equals(new_pid)) { layoutService.updatePid(old_pid, new_pid); } @@ -47,9 +46,9 @@ public class ConnectController { @RequestMapping(value = "/save", method = RequestMethod.POST) public PortalResponse insertConnect(@RequestBody Portal portal) { - if(!portal.getType().equals("connect")) { + if (!portal.getType().equals("connect")) { // EXCEPTION - MismatchingContent - throw new MismatchingContentException("Save Connect: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of connect"); + throw new MismatchingContentException("Save Connect: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of connect"); } PortalResponse portalResponse = portalService.insertPortal(portal); @@ -58,15 +57,15 @@ public class ConnectController { @RequestMapping(value = "/delete", method = RequestMethod.POST) public Boolean deleteConnect(@RequestBody List portals) { - for (String id: portals) { + for (String id : portals) { Portal portal = portalService.getPortalById(id); - if(portal == null) { + if (portal == null) { // EXCEPTION - Entity Not Found throw new ContentNotFoundException("Delete connect: Portal with id: " + id + " not found"); } - if(!portal.getType().equals("connect")) { + if (!portal.getType().equals("connect")) { // EXCEPTION - MismatchingContent - throw new MismatchingContentException("Delete Connect: Portal with id: "+id+" has type: "+portal.getType()+" instead of connect"); + throw new MismatchingContentException("Delete Connect: Portal with id: " + id + " has type: " + portal.getType() + " instead of connect"); } String pid = portalService.deletePortal(id); diff --git a/src/main/java/eu/dnetlib/uoaadmintools/controllers/CuratorController.java b/src/main/java/eu/dnetlib/uoaadmintools/controllers/CuratorController.java index a1fb139..98f2121 100644 --- a/src/main/java/eu/dnetlib/uoaadmintools/controllers/CuratorController.java +++ b/src/main/java/eu/dnetlib/uoaadmintools/controllers/CuratorController.java @@ -1,17 +1,15 @@ package eu.dnetlib.uoaadmintools.controllers; -import eu.dnetlib.uoaadmintools.dao.CuratorDAO; import eu.dnetlib.uoaadmintools.entities.curator.Curator; import eu.dnetlib.uoaadmintools.entities.curator.CuratorResponse; -import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; +import eu.dnetlib.uoaadmintools.services.CuratorService; +import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService; import org.apache.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.List; -import java.util.Optional; @RestController @CrossOrigin(origins = "*") @@ -19,34 +17,20 @@ public class CuratorController { private final Logger log = Logger.getLogger(this.getClass()); @Autowired - private CuratorDAO curatorDAO; + private CuratorService curatorService; @Autowired - private RolesUtils rolesUtils; + private AuthorizationService authorizationService; /** - * Return a list with curator. If list of emails does not existed return all curators, else return - * curators based on given list. + * Return a list with curator for a specific community * - * @param emails + * @param pid * @return */ - @RequestMapping(value = "/curator", method = RequestMethod.GET) - public List getCurators(@RequestParam(required = false) Optional emails) { - List curators = new ArrayList<>(); - if(emails.isPresent()) { - for(String email: emails.get().split(",")) { - Curator curator = curatorDAO.findByEmail(email); - if(curator != null) { - curators.add(new CuratorResponse(curator)); - } - } - } else { - for(Curator curator: curatorDAO.findAll()) { - curators.add(new CuratorResponse(curator)); - } - } - return curators; + @RequestMapping(value = "/{pid}/curator", method = RequestMethod.GET) + public List getCurators(@PathVariable String pid) { + return curatorService.getCurators(pid); } /** @@ -58,7 +42,7 @@ public class CuratorController { @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/curator/{id}", method = RequestMethod.GET) public Curator getCuratorById(@PathVariable String id) { - return curatorDAO.findById(id); + return curatorService.findById(id); } /** @@ -70,30 +54,21 @@ public class CuratorController { @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/curator", method = RequestMethod.POST) public Curator insertCurator(@RequestBody Curator curator) { - String aaiId = rolesUtils.getAaiId(); - curator.setId(aaiId); - return curatorDAO.save(curator); + String aaiId = authorizationService.getAaiId(); + curator.setId(aaiId.substring(0, aaiId.indexOf("@"))); + return curatorService.save(curator); } /** - * Delete all curators if list of emails does not exist or curators based on given list. + * Delete all curators for a spedific community. * - * @param emails + * @param pid */ @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") - @RequestMapping(value = "/curator", method = RequestMethod.DELETE) - public void deleteCurators(@RequestBody(required = false) Optional> emails) { - if(emails.isPresent()) { - for(String email: emails.get()) { - Curator curator = curatorDAO.findByEmail(email); - if(curator != null) { - curatorDAO.delete(curator.getId()); - } - } - } else { - curatorDAO.deleteAll(); - } + @RequestMapping(value = "/{pid}/curator", method = RequestMethod.DELETE) + public void deleteCurators(@PathVariable String pid) { + curatorService.deleteCurators(pid); } } diff --git a/src/main/java/eu/dnetlib/uoaadmintools/controllers/EmailController.java b/src/main/java/eu/dnetlib/uoaadmintools/controllers/EmailController.java index 39c623e..b40e5b8 100644 --- a/src/main/java/eu/dnetlib/uoaadmintools/controllers/EmailController.java +++ b/src/main/java/eu/dnetlib/uoaadmintools/controllers/EmailController.java @@ -2,11 +2,11 @@ package eu.dnetlib.uoaadmintools.controllers; import eu.dnetlib.uoaadmintools.dao.NotificationsDAO; import eu.dnetlib.uoaadmintools.entities.Notifications; -import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO; import eu.dnetlib.uoaadmintoolslibrary.emailSender.EmailSender; import eu.dnetlib.uoaadmintoolslibrary.entities.email.Email; import eu.dnetlib.uoaadmintoolslibrary.entities.email.EmailRecaptcha; +import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; import eu.dnetlib.uoaadmintoolslibrary.handlers.InvalidReCaptchaException; import eu.dnetlib.uoaadmintoolslibrary.recaptcha.VerifyRecaptcha; import org.apache.log4j.Logger; diff --git a/src/main/java/eu/dnetlib/uoaadmintools/controllers/ExploreController.java b/src/main/java/eu/dnetlib/uoaadmintools/controllers/ExploreController.java index fcec22f..9b8ac06 100644 --- a/src/main/java/eu/dnetlib/uoaadmintools/controllers/ExploreController.java +++ b/src/main/java/eu/dnetlib/uoaadmintools/controllers/ExploreController.java @@ -1,16 +1,16 @@ package eu.dnetlib.uoaadmintools.controllers; import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; -import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*; +import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse; import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException; import eu.dnetlib.uoaadmintoolslibrary.services.PortalService; import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; -import org.springframework.beans.factory.annotation.Autowired; -import java.util.*; +import java.util.List; @RestController @RequestMapping("/explore") diff --git a/src/main/java/eu/dnetlib/uoaadmintools/controllers/NotificationsController.java b/src/main/java/eu/dnetlib/uoaadmintools/controllers/NotificationsController.java index 11966c7..75fac21 100644 --- a/src/main/java/eu/dnetlib/uoaadmintools/controllers/NotificationsController.java +++ b/src/main/java/eu/dnetlib/uoaadmintools/controllers/NotificationsController.java @@ -2,10 +2,9 @@ package eu.dnetlib.uoaadmintools.controllers; import eu.dnetlib.uoaadmintools.dao.NotificationsDAO; import eu.dnetlib.uoaadmintools.entities.Notifications; -import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; -import eu.dnetlib.uoaadmintoolslibrary.entities.PortalType; -import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO; +import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; +import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException; import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; import org.apache.log4j.Logger; diff --git a/src/main/java/eu/dnetlib/uoaadmintools/controllers/PortalSubscribersController.java b/src/main/java/eu/dnetlib/uoaadmintools/controllers/PortalSubscribersController.java index 35f23d4..05ce988 100644 --- a/src/main/java/eu/dnetlib/uoaadmintools/controllers/PortalSubscribersController.java +++ b/src/main/java/eu/dnetlib/uoaadmintools/controllers/PortalSubscribersController.java @@ -1,21 +1,13 @@ package eu.dnetlib.uoaadmintools.controllers; - -//import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig; import eu.dnetlib.uoaadmintools.dao.PortalSubscribersDAO; import eu.dnetlib.uoaadmintools.dao.SubscriberDAO; import eu.dnetlib.uoaadmintools.entities.subscriber.PortalSubscribers; -import eu.dnetlib.uoaadmintools.entities.subscriber.Subscriber; -import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; -//import eu.dnetlib.uoaadmintools.handlers.utils.AuthorizationUtils; -//import eu.dnetlib.uoaadmintools.handlers.utils.UserInfo; -import eu.dnetlib.uoaadmintoolslibrary.responses.SingleValueWrapperResponse; import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO; +import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; +import eu.dnetlib.uoaadmintoolslibrary.responses.SingleValueWrapperResponse; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; - -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; /** diff --git a/src/main/java/eu/dnetlib/uoaadmintools/entities/Manager.java b/src/main/java/eu/dnetlib/uoaadmintools/entities/Manager.java new file mode 100644 index 0000000..0354e19 --- /dev/null +++ b/src/main/java/eu/dnetlib/uoaadmintools/entities/Manager.java @@ -0,0 +1,44 @@ +package eu.dnetlib.uoaadmintools.entities; + +public class Manager { + + private String id; + private String email; + private String name; + private String memberSince; + + public Manager() { + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMemberSince() { + return memberSince; + } + + public void setMemberSince(String memberSince) { + this.memberSince = memberSince; + } +} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/entities/curator/Response.java b/src/main/java/eu/dnetlib/uoaadmintools/entities/curator/Response.java new file mode 100644 index 0000000..5368b63 --- /dev/null +++ b/src/main/java/eu/dnetlib/uoaadmintools/entities/curator/Response.java @@ -0,0 +1,18 @@ +package eu.dnetlib.uoaadmintools.entities.curator; + +import eu.dnetlib.uoaadmintools.entities.Manager; + +public class Response { + private Manager[] response; + + public Response() { + } + + public Manager[] getResponse() { + return response; + } + + public void setResponse(Manager[] response) { + this.response = response; + } +} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/handlers/AuthorizationHandler.java b/src/main/java/eu/dnetlib/uoaadmintools/handlers/AuthorizationHandler.java deleted file mode 100644 index 2db32af..0000000 --- a/src/main/java/eu/dnetlib/uoaadmintools/handlers/AuthorizationHandler.java +++ /dev/null @@ -1,71 +0,0 @@ -//package eu.dnetlib.uoaadmintools.handlers; -// -//import eu.dnetlib.uoaadmintools.handlers.utils.AuthorizationUtils; -//import org.apache.log4j.Logger; -//import org.springframework.beans.factory.annotation.Value; -//import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; -// -//import javax.servlet.http.HttpServletRequest; -//import javax.servlet.http.HttpServletResponse; -//import java.util.List; -// -///** -// * Created by argirok on 23/2/2018. -// */ -//public class AuthorizationHandler extends HandlerInterceptorAdapter { -// private final Logger log = Logger.getLogger(this.getClass()); -// private AuthorizationUtils helper = new AuthorizationUtils(); -// private List allowedPostRequests; -// -// public AuthorizationHandler(String userInfoUrl, String originServer, List allowedPostRequests){ -// helper.setOriginServer(originServer); -// helper.setUserInfoUrl(userInfoUrl); -// this.allowedPostRequests = allowedPostRequests; -// } -// @Override -// public boolean preHandle( -// HttpServletRequest request, -// HttpServletResponse response, -// Object handler) throws Exception { -//// log.debug("request method " + request.getRemoteHost()); -//// log.debug("properties: " + helper.getOriginServer() + " "+ helper.getUserInfoUrl()); -//// log.debug(allowedPostRequests); -//// log.debug(allowedPostRequests.contains(request.getServletPath())); -//// log.debug(request.getServletPath()); -// if((request.getMethod().equals("POST") || request.getMethod().equals("DELETE")) && -// !allowedPostRequests.contains(request.getServletPath())) { -// //TODO check domain & check user info -// if(!this.helper.checkCookies(request) || !helper.isAuthorized(helper.getToken(request))){ -// -// response.setHeader("Access-Control-Allow-Credentials","true"); -// response.setHeader("Access-Control-Allow-Origin","*"); -// response.setHeader("Vary","Origin"); -// -// response.setStatus(403); -// response.sendError(403, "Forbidden: You don't have permission to access. Maybe you are not registered."); -// return false; -// } -// -// } -// return true; -// } -// -// -//// @Override -//// public void postHandle( -//// HttpServletRequest request, -//// HttpServletResponse response, -//// Object handler, -//// ModelAndView modelAndView) throws Exception { -//// log.info("I am here - postHandle "); -//// } -//// -//// @Override -//// public void afterCompletion( -//// HttpServletRequest request, -//// HttpServletResponse response, -//// Object handler, Exception ex) { -//// log.info("I am here - afterCompletion "); -//// } -// -//} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/handlers/CommunityNotFoundException.java b/src/main/java/eu/dnetlib/uoaadmintools/handlers/CommunityNotFoundException.java deleted file mode 100644 index 12ce1a0..0000000 --- a/src/main/java/eu/dnetlib/uoaadmintools/handlers/CommunityNotFoundException.java +++ /dev/null @@ -1,15 +0,0 @@ -package eu.dnetlib.uoaadmintools.handlers; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * Created by argirok on 6/3/2018. - */ -@ResponseStatus(HttpStatus.NO_CONTENT) -public class CommunityNotFoundException extends RuntimeException { - public CommunityNotFoundException(String message){ - super(message); - } -} - diff --git a/src/main/java/eu/dnetlib/uoaadmintools/handlers/ErrorDetails.java b/src/main/java/eu/dnetlib/uoaadmintools/handlers/ErrorDetails.java deleted file mode 100644 index 8a8abc8..0000000 --- a/src/main/java/eu/dnetlib/uoaadmintools/handlers/ErrorDetails.java +++ /dev/null @@ -1,17 +0,0 @@ -package eu.dnetlib.uoaadmintools.handlers; - - -import java.util.Date; - -public class ErrorDetails { - private Date timestamp; - private String message; - private String details; - - public ErrorDetails(Date timestamp, String message, String details) { - super(); - this.timestamp = timestamp; - this.message = message; - this.details = details; - } -} \ No newline at end of file diff --git a/src/main/java/eu/dnetlib/uoaadmintools/handlers/ExceptionsHandler.java b/src/main/java/eu/dnetlib/uoaadmintools/handlers/ExceptionsHandler.java deleted file mode 100644 index 0b7e331..0000000 --- a/src/main/java/eu/dnetlib/uoaadmintools/handlers/ExceptionsHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -package eu.dnetlib.uoaadmintools.handlers; - -import eu.dnetlib.uoaadmintoolslibrary.responses.ExceptionResponse; - -import eu.dnetlib.uoaadmintoolslibrary.handlers.InvalidReCaptchaException; -import org.apache.log4j.Logger; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.MissingServletRequestParameterException; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; - -@ControllerAdvice -public class ExceptionsHandler { - private final Logger log = Logger.getLogger(this.getClass()); - -// @ExceptionHandler(MissingServletRequestParameterException.class) -// public ResponseEntity invalidInput(Exception ex) { -// ExceptionResponse response = new ExceptionResponse(); -// response.setErrorCode("Validation Error"); -// response.setErrorMessage("Invalid inputs."); -// response.setErrors(ex.getMessage()); -// log.debug("invalidInput exception"); -// -// return new ResponseEntity(response, HttpStatus.BAD_REQUEST); -// } -// @ExceptionHandler(ContentNotFoundException2.class) -// public ResponseEntity contentNotFound(Exception ex) { -// ExceptionResponse response = new ExceptionResponse(); -// response.setErrorCode("No content found"); -// response.setErrorMessage(ex.getMessage()); -// response.setErrors(ex.getMessage()); -// log.debug("contentNotFound exception" + response.getErrorCode()+ " "+response.getErrorMessage()); -// return new ResponseEntity(response, HttpStatus.NOT_FOUND); -// } -// @ExceptionHandler(NullPointerException.class) -// public ResponseEntity nullPointerException(Exception ex) { -// ExceptionResponse response = new ExceptionResponse(); -// response.setErrorCode("Null pointer Exception"); -// response.setErrorMessage("Null pointer Exception"); -// response.setErrors(ex.getMessage()); -// log.debug("nullPointerException exception"); -// return new ResponseEntity(response, HttpStatus.BAD_REQUEST); -// } -// @ExceptionHandler(InvalidReCaptchaException.class) -// public ResponseEntity invalidReCaptchaException(Exception ex) { -// ExceptionResponse response = new ExceptionResponse(); -// response.setErrorCode("Invalid ReCaptcha Exception"); -// response.setErrorMessage("Invalid ReCaptcha Exception"); -// response.setErrors(ex.getMessage()); -// log.debug("invalidReCaptchaException exception"); -// return new ResponseEntity(response, HttpStatus.BAD_REQUEST); -// } -} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/handlers/utils/AuthorizationUtils.java b/src/main/java/eu/dnetlib/uoaadmintools/handlers/utils/AuthorizationUtils.java deleted file mode 100644 index 6ff1444..0000000 --- a/src/main/java/eu/dnetlib/uoaadmintools/handlers/utils/AuthorizationUtils.java +++ /dev/null @@ -1,253 +0,0 @@ -//package eu.dnetlib.uoaadmintools.handlers.utils; -// -//import org.apache.log4j.Logger; -// -//import javax.servlet.http.Cookie; -//import javax.servlet.http.HttpServletRequest; -//import java.io.BufferedReader; -//import java.io.InputStreamReader; -//import java.io.StringReader; -//import java.net.HttpURLConnection; -//import java.net.URL; -//import java.util.Enumeration; -// -//import com.google.gson.Gson; -// -///** -// * Created by argirok on 27/2/2018. -// */ -//public class AuthorizationUtils { -// private final Logger log = Logger.getLogger(this.getClass()); -// private String userInfoUrl = null; -//// private String communityAPI =""; -//// List adminRoles = new ArrayList(Arrays.asList("Super Administrator", "Portal Administrator")); -// private String originServer= null; -// public Boolean checkCookies(HttpServletRequest request){ -// Boolean valid = true; -// String cookieValue = this.getCookie(request,"AccessToken"); -// if(cookieValue == null || cookieValue.isEmpty()){ -// log.info("no cookie available "); -// valid = false; -// }else { -// String headerValue = this.getHeadersInfo(request, "x-xsrf-token"); -// if(headerValue == null || headerValue.isEmpty()){ -// log.info("no header available "); -// valid = false; -// }else{ -// if(!cookieValue.equals(headerValue)){ -// log.info("no proper header or cookie "); -// valid = false; -// }else if(!hasValidOrigin(this.getHeadersInfo(request, "origin"))){ -// log.info("no proper origin "); -// valid = false; -// } -// } -// } -// return valid; -// } -// public String getToken(HttpServletRequest request){ -// return this.getHeadersInfo(request, "x-xsrf-token"); -// } -// private String getCookie(HttpServletRequest request, String cookieName){ -// if(request.getCookies() == null){ -// return null; -// } -// for(Cookie c: request.getCookies()){ -//// log.debug("cookie "+ c.getName()+ " "+ c.getValue()); -// if(c.getName().equals(cookieName)){ -// return c.getValue(); -// } -// -// } -// return null; -// } -// private String getHeadersInfo(HttpServletRequest request, String name) { -// -// Enumeration headerNames = request.getHeaderNames(); -// while (headerNames.hasMoreElements()) { -// String key = (String) headerNames.nextElement(); -// String value = request.getHeader(key); -//// log.debug(" key: "+ key+" value: "+ value); -// if(name.equals(key)){ -// return value; -// } -// } -// return null; -// } -// public boolean hasValidOrigin(String origin) { -// if (origin != null && origin.indexOf(originServer)!=-1) { -// return true; -// } -// log.debug("Not valid origin. Origin server is \"" + origin + "\", but expected value is \"" + originServer + "\". If the expec cted value is not right, check properties file. "); -// return false; -// } -// public UserInfo getUserInfo(String accessToken){ -// String url=userInfoUrl+accessToken; -// URL obj = null; -// String responseStr=null; -//// log.debug("User info url is "+url); -// -// try { -// obj = new URL(url); -// HttpURLConnection con = (HttpURLConnection) obj.openConnection(); -// if (con.getResponseCode() != 200) { -// log.debug("User info response code is: " + con.getResponseCode()); -// return null; -// } -// BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); -// StringBuffer response = new StringBuffer(); -// String inputLine; -// while ((inputLine = in.readLine()) != null) { -// response.append(inputLine).append("\n"); -// } -// in.close(); -// responseStr = response.toString(); -// }catch(Exception e){ -// log.error("An error occured while trying to fetch user info ",e); -// return null; -// } -// return json2UserInfo(responseStr); -// } -// private UserInfo json2UserInfo(String json) { -// -//// log.debug("Try to create userInfo class from json: "+json); -// if (json == null){ -// return null; -// } -// -// BufferedReader br = new BufferedReader(new StringReader(json)); -// //convert the json string back to object -// Gson gson = new Gson(); -// UserInfo userInfo = null; -// try { -// userInfo = gson.fromJson(br, UserInfo.class); -// }catch(Exception e){ -// log.debug("Error in parsing json response. Given json is : "+json, e); -// return null; -// } -// -//// log.debug("Original response.........: "+userInfo.toString()); -// try { -// if(userInfo != null && userInfo.getEdu_person_entitlements() != null ) { -// -// for (int i = 0; i < userInfo.getEdu_person_entitlements().size(); i++) { -// String role = userInfo.getEdu_person_entitlements().get(i); -//// log.debug("AAI role: "+role); -// role = role.split(":")[role.split(":").length-1]; -// role = role.replace("+"," "); -//// log.debug("Adding parsed role : "+role); -// userInfo.getEdu_person_entitlements().set(i,role); -// } -// } -// }catch(Exception e){ -// log.debug("Error in parsing Edu_person_entitlements : ",e); -// return null; -// } -//// log.debug("After handling roles : "+userInfo.toString()); -// -// -// return userInfo; -// } -// public boolean isAuthorized(String token) { -// UserInfo userInfo = getUserInfo(token); -// if (userInfo != null ) { -// return true; -// } else { -// log.debug(" User has no Valid UserInfo"); -// return false; -// } -// -// } -// -// public String getUserInfoUrl() { -// return userInfoUrl; -// } -// -// public String getOriginServer() { -// return originServer; -// } -// -// public void setUserInfoUrl(String userInfoUrl) { -// this.userInfoUrl = userInfoUrl; -// } -// -// public void setOriginServer(String originServer) { -// this.originServer = originServer; -// } -// // private boolean hasRole(List givenRoles, List authorizedRoles) { -//// log.debug("It's registered with role " + givenRoles); -//// for (String gRole : givenRoles) { -//// if (authorizedRoles.indexOf(gRole) != -1) { -//// return true; -//// } -//// } -//// log.debug("Not Authorized. Authorized roles are" + authorizedRoles); -//// return false; -//// -//// } -//// private boolean isCommunityManager(String community, String email) { -//// -//// CommunityInfo communityInfo = getCommunityInfo(community); -//// if(communityInfo != null && communityInfo.getManagers() != null ) { -//// -//// for (int i = 0; i < communityInfo.getManagers().size(); i++) { -//// String manager = communityInfo.getManagers().get(i); -//// log.debug("Community manager: "+manager); -//// -//// } -//// } -//// return false; -//// -//// } -//// private CommunityInfo getCommunityInfo(String community) { -//// String url = userInfoUrl + community; -//// URL obj = null; -//// String responseStr = null; -//// log.debug("Community info url is " + url); -//// -//// try { -//// obj = new URL(url); -//// HttpURLConnection con = (HttpURLConnection) obj.openConnection(); -//// log.debug("User info response code is: " + con.getResponseCode()); -//// if (con.getResponseCode() != 200) { -//// return null; -//// } -//// BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); -//// StringBuffer response = new StringBuffer(); -//// String inputLine; -//// while ((inputLine = in.readLine()) != null) { -//// response.append(inputLine).append("\n"); -//// } -//// in.close(); -//// responseStr = response.toString(); -//// } catch (Exception e) { -//// log.error("An error occured while trying to fetch user info ", e); -//// return null; -//// } -//// return json2CommunityInfo(community); -//// } -//// private CommunityInfo json2CommunityInfo(String json){ -//// -//// log.debug("Try to create CommunityInfo class from json: "+json); -//// if (json == null){ -//// return null; -//// } -//// -//// BufferedReader br = new BufferedReader(new StringReader(json)); -//// //convert the json string back to object -//// Gson gson = new Gson(); -//// CommunityInfo communityInfo = null; -//// try { -//// communityInfo = gson.fromJson(br, CommunityInfo.class); -//// }catch(Exception e){ -//// log.debug("Error in parsing json response. Given json is : "+json, e); -//// return null; -//// } -//// -//// log.debug("Original response.........: "+communityInfo.toString()); -//// -//// -//// -//// return communityInfo; -//// } -//} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/handlers/utils/CommunityInfo.java b/src/main/java/eu/dnetlib/uoaadmintools/handlers/utils/CommunityInfo.java deleted file mode 100644 index d95618d..0000000 --- a/src/main/java/eu/dnetlib/uoaadmintools/handlers/utils/CommunityInfo.java +++ /dev/null @@ -1,81 +0,0 @@ -//package eu.dnetlib.uoaadmintools.handlers.utils; -// -//import com.google.gson.Gson; -//import org.apache.log4j.Logger; -// -//import java.io.BufferedReader; -//import java.io.InputStreamReader; -//import java.io.StringReader; -//import java.net.HttpURLConnection; -//import java.net.URL; -//import java.util.ArrayList; -//import java.util.List; -// -///** -// * Created by argirok on 27/2/2018. -// */ -//public class CommunityInfo { -// -// List managers = new ArrayList(); -// private final Logger log = Logger.getLogger(this.getClass()); -// -// public List getManagers() { -// return managers; -// } -// -// public void setManagers(List managers) { -// this.managers = managers; -// } -// -// private CommunityInfo getCommunityInfo(String communityAPI, String community) { -// String url = communityAPI + community; -// URL obj = null; -// String responseStr = null; -// log.debug("Community info url is " + url); -// -// try { -// obj = new URL(url); -// HttpURLConnection con = (HttpURLConnection) obj.openConnection(); -// log.debug("User info response code is: " + con.getResponseCode()); -// if (con.getResponseCode() != 200) { -// return null; -// } -// BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); -// StringBuffer response = new StringBuffer(); -// String inputLine; -// while ((inputLine = in.readLine()) != null) { -// response.append(inputLine).append("\n"); -// } -// in.close(); -// responseStr = response.toString(); -// } catch (Exception e) { -// log.error("An error occured while trying to fetch user info ", e); -// return null; -// } -// return json2CommunityInfo(community); -// } -// private CommunityInfo json2CommunityInfo(String json){ -// -// log.debug("Try to create CommunityInfo class from json: "+json); -// if (json == null){ -// return null; -// } -// -// BufferedReader br = new BufferedReader(new StringReader(json)); -// //convert the json string back to object -// Gson gson = new Gson(); -// CommunityInfo communityInfo = null; -// try { -// communityInfo = gson.fromJson(br, CommunityInfo.class); -// }catch(Exception e){ -// log.debug("Error in parsing json response. Given json is : "+json, e); -// return null; -// } -// -// log.debug("Original response.........: "+communityInfo.toString()); -// -// -// -// return communityInfo; -// } -//} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/handlers/utils/UserInfo.java b/src/main/java/eu/dnetlib/uoaadmintools/handlers/utils/UserInfo.java deleted file mode 100644 index 127f799..0000000 --- a/src/main/java/eu/dnetlib/uoaadmintools/handlers/utils/UserInfo.java +++ /dev/null @@ -1,46 +0,0 @@ -//package eu.dnetlib.uoaadmintools.handlers.utils; -// -//import java.util.ArrayList; -//import java.util.List; -// -///** -// * Created by argirok on 23/6/2017. -// */ -//public class UserInfo { -// String name; -// String email; -// List edu_person_entitlements = new ArrayList(); -// -// @Override -// public String toString() { -// return "UserInfo{" + -// "name='" + name + '\'' + -// ", email='" + email + '\'' + -// ", edu_person_entitlements=" + edu_person_entitlements + -// '}'; -// } -// -// public String getName() { -// return name; -// } -// -// public void setName(String name) { -// this.name = name; -// } -// -// public String getEmail() { -// return email; -// } -// -// public void setEmail(String email) { -// this.email = email; -// } -// -// public List getEdu_person_entitlements() { -// return edu_person_entitlements; -// } -// -// public void setEdu_person_entitlements(List edu_person_entitlements) { -// this.edu_person_entitlements = edu_person_entitlements; -// } -//} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/services/CuratorService.java b/src/main/java/eu/dnetlib/uoaadmintools/services/CuratorService.java new file mode 100644 index 0000000..7d5a39d --- /dev/null +++ b/src/main/java/eu/dnetlib/uoaadmintools/services/CuratorService.java @@ -0,0 +1,57 @@ +package eu.dnetlib.uoaadmintools.services; + + +import eu.dnetlib.uoaadmintools.dao.CuratorDAO; +import eu.dnetlib.uoaadmintools.entities.Manager; +import eu.dnetlib.uoaadmintools.entities.curator.Curator; +import eu.dnetlib.uoaadmintools.entities.curator.CuratorResponse; +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class CuratorService { + + private final Logger log = Logger.getLogger(this.getClass()); + + @Autowired + private CuratorDAO curatorDAO; + + @Autowired + private ManagerService managerService; + + + public List getCurators(String pid) { + List curators = new ArrayList<>(); + + for (Manager manager : managerService.getManagers(pid)) { + log.info(manager.getEmail()); + Curator curator = curatorDAO.findByEmail(manager.getEmail()); + if (curator != null) { + curators.add(new CuratorResponse(curator)); + } + } + return curators; + } + + public Curator findById(String id) { + return curatorDAO.findById(id); + } + + public Curator save(Curator curator) { + return curatorDAO.save(curator); + } + + public void deleteCurators(String pid) { + for (Manager manager : managerService.getManagers(pid)) { + Curator curator = curatorDAO.findByEmail(manager.getEmail()); + if (curator != null) { + curatorDAO.delete(curator.getId()); + } + } + } + +} \ No newline at end of file diff --git a/src/main/java/eu/dnetlib/uoaadmintools/services/ManagerService.java b/src/main/java/eu/dnetlib/uoaadmintools/services/ManagerService.java new file mode 100644 index 0000000..e9f075c --- /dev/null +++ b/src/main/java/eu/dnetlib/uoaadmintools/services/ManagerService.java @@ -0,0 +1,31 @@ +package eu.dnetlib.uoaadmintools.services; + +import eu.dnetlib.uoaadmintools.configuration.properties.ManagersApiConfig; +import eu.dnetlib.uoaadmintools.entities.Manager; +import eu.dnetlib.uoaadmintools.entities.curator.Response; +import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class ManagerService { + + @Autowired + private ManagersApiConfig config; + + @Autowired + private RestTemplate restTemplate; + + public Manager[] getManagers(String pid) { + ResponseEntity responseEntity = restTemplate.getForEntity(config.getEmail().replace("{community}", pid), Response.class); + Response response = responseEntity.getBody(); + if (response != null && responseEntity.getStatusCode() == HttpStatus.OK) { + return response.getResponse(); + } else { + throw new ContentNotFoundException("No managers has been found for community " + pid); + } + } +} diff --git a/src/main/resources/admintools.properties b/src/main/resources/admintools.properties index 02b41e8..659eda4 100644 --- a/src/main/resources/admintools.properties +++ b/src/main/resources/admintools.properties @@ -2,16 +2,18 @@ #admintool.security.userInfoUrl = http://scoobydoo.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken= #admintool.security.originServer = .di.uoa.gr #admintool.security.postsAllowed = /contact,/contact/ -#admintool.mail.host = smtp.gmail.com -#admintool.mail.port = 587 -#admintool.mail.auth = true -#admintool.mail.from = openaire.test@gmail.com -#admintool.mail.username = openaire.test@gmail.com -#admintool.mail.password = -#admintool.google.secret = 6LcVtFIUAAAAAIlEaz6Am2PBC3j5lHG7vBo6uW4_ -#admintool.mongodb.host=localhost -#admintool.mongodb.port=27017 -#admintool.mongodb.database=openaire_admin_beta_20191105 +admintool.mail.host = smtp.gmail.com +admintool.mail.port = 587 +admintool.mail.auth = true +admintool.mail.from = openaire.test@gmail.com +admintool.mail.username = openaire.test@gmail.com +admintool.mail.password = +admintool.google.secret = 6LcVtFIUAAAAAIlEaz6Am2PBC3j5lHG7vBo6uW4_ +admintool.mongodb.host=localhost +admintool.mongodb.port=27017 +admintool.mongodb.database=openaire_admin +admintool.managers.api.id = http://mpagasas.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/community/{community}/managers/id +admintool.managers.api.email = http://mpagasas.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/community/{community}/managers/email #beta #admintool.security.userInfoUrl = https://beta.services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=