From a265d414a45b511106c28a6b0d4dac4c773ae384 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Fri, 26 Feb 2021 12:44:44 +0000 Subject: [PATCH] [Trunk | Admin Tools Library]: 1. PageHelpContentDAO.java & MongoDBPageHelpContentDAO.java: Added method "findByPortalAndPageOrderByPlacementAscOrderAsc()" to get page help contents for a specific portal and page. 2. PageHelpContentService.java: Added method "getPageHelpContentsBasic()". 3. DivHelpContentDAO.java & MongoDBDivHelpContentDAO.java: Added method "findByPortalAndPage()" to get div help contents for a specific portal and page. 4. DivHelpContentService.java: Added method "getDivHelpContentsBasic()". 5. AdminPortalRelationsController.java: a. Added methods "public List getPageHelpContentsByPageId()" (/{portalType}/{pid}/{pageId}/pagehelpcontent), "public Map countPageHelpContentsForPages()" (/{portalType}/{pid}/pagehelpcontent/page/count), "public List getDivHelpContentsByPageId()" (/{portalType}/{pid}/{pageId}/divhelpcontent), "public Map countDivHelpContentsForPages()" (/{portalType}/{pid}/divhelpcontent/page/count) b. Added @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") in methods: "public List getPageHelpContents()" and "public List getDivHelpContents()". 6. RolesUtils.java: [Bug fix] In method "getEmail()" call authorizationService.getEmail(). --- .../AdminPortalRelationsController.java | 103 ++++++++++++++---- .../dao/DivHelpContentDAO.java | 1 + .../MongoDBDAOs/MongoDBDivHelpContentDAO.java | 1 + .../MongoDBPageHelpContentDAO.java | 1 + .../dao/PageHelpContentDAO.java | 1 + .../handlers/utils/RolesUtils.java | 2 +- .../services/DivHelpContentService.java | 25 +++++ .../services/PageHelpContentService.java | 24 ++++ 8 files changed, 134 insertions(+), 24 deletions(-) diff --git a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/controllers/AdminPortalRelationsController.java b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/controllers/AdminPortalRelationsController.java index db1439f..4a283c4 100644 --- a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/controllers/AdminPortalRelationsController.java +++ b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/controllers/AdminPortalRelationsController.java @@ -4,13 +4,16 @@ import eu.dnetlib.uoaadmintoolslibrary.entities.*; import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*; import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException; +import eu.dnetlib.uoaadmintoolslibrary.responses.SingleValueWrapperResponse; import eu.dnetlib.uoaadmintoolslibrary.services.*; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.security.access.prepost.PreAuthorize; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; @RestController @@ -67,24 +70,50 @@ public class AdminPortalRelationsController { // return portalService.getDivHelpContentsByPosition(pid, page, active); // } + // not used by portals + @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") @RequestMapping(value = "/{pid}/divhelpcontent", method = RequestMethod.GET) public List getDivHelpContents(@PathVariable PortalType portalType, @PathVariable(value = "pid") String pid) { return divHelpContentService.getDivHelpContents(pid, null, null, null); } - @RequestMapping(value = "/{pid}/divhelpcontent/{id}", method = RequestMethod.GET) - public DivHelpContent getDivHelpContent(@PathVariable PortalType portalType, - @PathVariable(value = "pid") String pid, - @PathVariable(value = "id") String id) { - DivHelpContent divHelpContent = divHelpContentService.getDivHelpContent(id); - if(divHelpContent == null) { - throw new ContentNotFoundException("DivHelpContent with id: "+id+" not found"); - } +// @RequestMapping(value = "/{pid}/divhelpcontent/{id}", method = RequestMethod.GET) +// public DivHelpContent getDivHelpContent(@PathVariable PortalType portalType, +// @PathVariable(value = "pid") String pid, +// @PathVariable(value = "id") String id) { +// DivHelpContent divHelpContent = divHelpContentService.getDivHelpContent(id); +// if(divHelpContent == null) { +// throw new ContentNotFoundException("DivHelpContent with id: "+id+" not found"); +// } +// +// Portal portal = portalService.getPortalById(divHelpContent.getPortal()); +// portalService.checkPortalInfo(pid, portalType.name(), portal, divHelpContent.getPortal(), "id"); +// return divHelpContent; +// } - Portal portal = portalService.getPortalById(divHelpContent.getPortal()); - portalService.checkPortalInfo(pid, portalType.name(), portal, divHelpContent.getPortal(), "id"); - return divHelpContent; + @RequestMapping(value = "/{pid}/{pageId}/divhelpcontent", method = RequestMethod.GET) + public List getDivHelpContentsByPageId(@PathVariable PortalType portalType, + @PathVariable(value = "pid") String pid, + @PathVariable(value = "pageId") String pageId) { + return divHelpContentService.getDivHelpContentsBasic(pid, portalType.name(), pageId); + } + + @RequestMapping(value = "/{pid}/divhelpcontent/page/count", method = RequestMethod.GET) + public Map countDivHelpContentsForPages(@PathVariable PortalType portalType, + @PathVariable(value = "pid") String pid) { + Map mapCount = new HashMap(); + + List pages = pageService.getAllPages(pid, null, null); + for(Page page : pages){ + List divHelpContents = divHelpContentService.getDivHelpContentsBasic(pid, portalType.name(), page.getId()); + if (divHelpContents == null) { + mapCount.put(page.getId(), 0); + } else { + mapCount.put(page.getId(), divHelpContents.size()); + } + } + return mapCount; } @PreAuthorize("hasAnyAuthority(" + @@ -240,26 +269,54 @@ public class AdminPortalRelationsController { // return portalService.getPageHelpContentsByPosition(pid, page, active); // } + // not used by portals + @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") @RequestMapping(value = "/{pid}/pagehelpcontent", method = RequestMethod.GET) public List getPageHelpContents(@PathVariable PortalType portalType, @PathVariable(value = "pid") String pid) { return pageHelpContentService.getPageHelpContents(pid, null, null, null, null, null); } - @RequestMapping(value = "/{pid}/pagehelpcontent/{id}", method = RequestMethod.GET) - public PageHelpContent getPageHelpContent(@PathVariable PortalType portalType, - @PathVariable(value = "pid") String pid, - @PathVariable(value = "id") String id) { - PageHelpContent pageHelpContent = pageHelpContentService.getPageHelpContent(id); - if(pageHelpContent == null) { - throw new ContentNotFoundException("PageHelpContent with id: "+id+" not found"); - } - - Portal portal = portalService.getPortalById(pageHelpContent.getPortal()); - portalService.checkPortalInfo(pid, portalType.name(), portal, pageHelpContent.getPortal(), "id"); - return pageHelpContent; + // used + @RequestMapping(value = "/{pid}/{pageId}/pagehelpcontent", method = RequestMethod.GET) + public List getPageHelpContentsByPageId(@PathVariable PortalType portalType, + @PathVariable(value = "pid") String pid, + @PathVariable(value = "pageId") String pageId) { + return pageHelpContentService.getPageHelpContentsBasic(pid, portalType.name(), pageId); } + // used + @RequestMapping(value = "/{pid}/pagehelpcontent/page/count", method = RequestMethod.GET) + public Map countPageHelpContentsForPages(@PathVariable PortalType portalType, + @PathVariable(value = "pid") String pid) { + Map mapCount = new HashMap(); + + List pages = pageService.getAllPages(pid, null, null); + for(Page page : pages){ + List pageHelpContents = pageHelpContentService.getPageHelpContentsBasic(pid, portalType.name(), page.getId()); + if (pageHelpContents == null) { + mapCount.put(page.getId(), 0); + } else { + mapCount.put(page.getId(), pageHelpContents.size()); + } + } + return mapCount; + } + +// @RequestMapping(value = "/{pid}/pagehelpcontent/{id}", method = RequestMethod.GET) +// public PageHelpContent getPageHelpContent(@PathVariable PortalType portalType, +// @PathVariable(value = "pid") String pid, +// @PathVariable(value = "id") String id) { +// PageHelpContent pageHelpContent = pageHelpContentService.getPageHelpContent(id); +// if(pageHelpContent == null) { +// throw new ContentNotFoundException("PageHelpContent with id: "+id+" not found"); +// } +// +// Portal portal = portalService.getPortalById(pageHelpContent.getPortal()); +// portalService.checkPortalInfo(pid, portalType.name(), portal, pageHelpContent.getPortal(), "id"); +// return pageHelpContent; +// } + @PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN, " + "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))") diff --git a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/DivHelpContentDAO.java b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/DivHelpContentDAO.java index 0943a2d..31fe5b2 100644 --- a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/DivHelpContentDAO.java +++ b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/DivHelpContentDAO.java @@ -14,6 +14,7 @@ public interface DivHelpContentDAO { List findByPortalAndIsActive(String portalId, boolean isActive); List findByDivIdAndIsActive(String divId, boolean isActive); List findByPortalAndDivIdAndIsActive(String portalId, String divId, boolean isActive); + List findByPortalAndPage(String portalId, String page); DivHelpContent findById(String Id); diff --git a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBDivHelpContentDAO.java b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBDivHelpContentDAO.java index f520ca1..a4a7190 100644 --- a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBDivHelpContentDAO.java +++ b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBDivHelpContentDAO.java @@ -17,6 +17,7 @@ public interface MongoDBDivHelpContentDAO extends DivHelpContentDAO, MongoReposi List findByPortalAndIsActive(String portalId, boolean isActive); List findByDivIdAndIsActive(String divId, boolean isActive); List findByPortalAndDivIdAndIsActive(String portalId, String divId, boolean isActive); + List findByPortalAndPage(String portalId, String page); DivHelpContent findById(String Id); diff --git a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBPageHelpContentDAO.java b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBPageHelpContentDAO.java index 6266d6a..bc163ee 100644 --- a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBPageHelpContentDAO.java +++ b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/MongoDBDAOs/MongoDBPageHelpContentDAO.java @@ -21,6 +21,7 @@ public interface MongoDBPageHelpContentDAO extends PageHelpContentDAO, MongoRepo List findByPlacementAndIsActiveOrderByOrderAsc(String position, boolean isActive); List findByPlacementAndIsPriorToOrderByOrderAsc(String position, boolean isPriorTo); List findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(boolean isActive, boolean isPriorTo); + List findByPortalAndPageOrderByPlacementAscOrderAsc(String portalId, String page); List findByPortalOrderByPlacementAscOrderAsc(String portalId); List findByPlacementOrderByOrderAsc(String postion); List findByIsActiveOrderByPlacementAscOrderAsc(boolean isActive); diff --git a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/PageHelpContentDAO.java b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/PageHelpContentDAO.java index f6ae319..ad8a413 100644 --- a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/PageHelpContentDAO.java +++ b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/dao/PageHelpContentDAO.java @@ -19,6 +19,7 @@ public interface PageHelpContentDAO { List findByPlacementAndIsPriorToOrderByOrderAsc(String position, boolean isPriorTo); List findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(boolean isActive, boolean isPriorTo); List findByPortalOrderByPlacementAscOrderAsc(String portalId); + List findByPortalAndPageOrderByPlacementAscOrderAsc(String portalId, String page); List findByPlacementOrderByOrderAsc(String postion); List findByIsActiveOrderByPlacementAscOrderAsc(boolean isActive); List findByIsPriorToOrderByPlacementAscOrderAsc(boolean isPriorTo); diff --git a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/handlers/utils/RolesUtils.java b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/handlers/utils/RolesUtils.java index b9b5570..450b522 100644 --- a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/handlers/utils/RolesUtils.java +++ b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/handlers/utils/RolesUtils.java @@ -20,7 +20,7 @@ public class RolesUtils { } public String getEmail() { - return authorizationService.getAaiId(); + return authorizationService.getEmail(); } public String getAaiId() { diff --git a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/services/DivHelpContentService.java b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/services/DivHelpContentService.java index febf210..aab79d0 100644 --- a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/services/DivHelpContentService.java +++ b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/services/DivHelpContentService.java @@ -90,6 +90,31 @@ public class DivHelpContentService { return divHelpContentResponses; } + + public List getDivHelpContentsBasic(String pid, String portalType, String pageId) { + List divHelpContents = null; + + Portal _portal = null; + String portalId = null; + if(pid != null) { + _portal = portalService.getPortal(pid); + portalService.checkPortalInfo(pid, portalType, _portal, pid, "pid"); + if(_portal != null) { + portalId = _portal.getId(); + } + } + + if(pid != null && pageId != null) { + divHelpContents = divHelpContentDAO.findByPortalAndPage(portalId, pageId); + } else if(pid != null) { + divHelpContents = divHelpContentDAO.findByPortal(portalId); + } else { + divHelpContents = divHelpContentDAO.findAll(); + } + + return divHelpContents; + } + public DivHelpContent getDivHelpContent(String id) { return divHelpContentDAO.findById(id); } diff --git a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/services/PageHelpContentService.java b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/services/PageHelpContentService.java index 92818f0..ea3ef5f 100644 --- a/src/main/java/eu/dnetlib/uoaadmintoolslibrary/services/PageHelpContentService.java +++ b/src/main/java/eu/dnetlib/uoaadmintoolslibrary/services/PageHelpContentService.java @@ -89,6 +89,30 @@ public class PageHelpContentService { return pageHelpContentResponses; } + public List getPageHelpContentsBasic(String pid, String portalType, String pageId) { + List pageHelpContents = null; + + Portal _portal = null; + String portalId = null; + if(pid != null) { + _portal = portalService.getPortal(pid); + portalService.checkPortalInfo(pid, portalType, _portal, pid, "pid"); + if(_portal != null) { + portalId = _portal.getId(); + } + } + + if(pid != null && pageId != null) { + pageHelpContents = pageHelpContentDAO.findByPortalAndPageOrderByPlacementAscOrderAsc(portalId, pageId); + } else if(pid != null) { + pageHelpContents = pageHelpContentDAO.findByPortalOrderByPlacementAscOrderAsc(portalId); + } else { + pageHelpContents = pageHelpContentDAO.findAllByOrderByPlacementAscOrderAsc(); + } + + return pageHelpContents; + } + public void deleteAllPageHelpContents() { pageHelpContentDAO.deleteAll(); }