Revision 60495
Added by Konstantina Galouni about 3 years ago
PageHelpContentService.java | ||
---|---|---|
4 | 4 |
import eu.dnetlib.uoaadmintoolslibrary.entities.Page; |
5 | 5 |
import eu.dnetlib.uoaadmintoolslibrary.entities.PageHelpContent; |
6 | 6 |
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; |
7 |
import eu.dnetlib.uoaadmintoolslibrary.entities.PortalType; |
|
7 | 8 |
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PageHelpContentResponse; |
8 | 9 |
|
10 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; |
|
11 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException; |
|
9 | 12 |
import org.apache.log4j.Logger; |
10 | 13 |
import org.springframework.beans.factory.annotation.Autowired; |
11 | 14 |
import org.springframework.stereotype.Service; |
... | ... | |
108 | 111 |
return pageHelpContentDAO.findById(id); |
109 | 112 |
} |
110 | 113 |
|
111 |
public List<String> togglePageHelpContent(List<String> pageHelpContents, String status) throws Exception { |
|
114 |
public List<String> togglePageHelpContent(List<String> pageHelpContents, String status, String pid, PortalType portalType) throws Exception { |
|
115 |
Portal portal = portalService.getPortal(pid); |
|
116 |
portalService.checkPortalInfo(pid, portalType.name(), portal, pid, "pid"); |
|
117 |
|
|
112 | 118 |
for (String id: pageHelpContents) { |
113 |
log.debug("Id of pageHelpContent: "+id); |
|
119 |
// log.debug("Id of pageHelpContent: "+id);
|
|
114 | 120 |
PageHelpContent pageHelpContent = pageHelpContentDAO.findById(id); |
121 |
if(pageHelpContent == null) { |
|
122 |
throw new ContentNotFoundException("Page help content with id: " + id + " not found"); |
|
123 |
} |
|
124 |
if(!pageHelpContent.getPortal().equals(portal.getId())) { |
|
125 |
throw new MismatchingContentException("["+portalType+ " - "+ pid+"] Conflicting page help content: portal id: "+pageHelpContent.getPortal()); |
|
126 |
} |
|
115 | 127 |
pageHelpContent.setIsActive(Boolean.parseBoolean(status)); |
116 | 128 |
pageHelpContentDAO.save(pageHelpContent); |
117 | 129 |
} |
... | ... | |
122 | 134 |
pageHelpContentDAO.delete(id); |
123 | 135 |
} |
124 | 136 |
|
125 |
public Boolean deletePageHelpContents(List<String> pageHelpContents) throws Exception { |
|
137 |
public Boolean deletePageHelpContents(List<String> pageHelpContents, String pid, PortalType portalType) throws Exception { |
|
138 |
Portal portal = portalService.getPortal(pid); |
|
139 |
portalService.checkPortalInfo(pid, portalType.name(), portal, pid, "pid"); |
|
140 |
|
|
126 | 141 |
for (String id: pageHelpContents) { |
142 |
PageHelpContent pageHelpContent = getPageHelpContent(id); |
|
143 |
if(pageHelpContent == null) { |
|
144 |
throw new ContentNotFoundException("Page help content with id: " + id + " not found"); |
|
145 |
} |
|
146 |
if(!pageHelpContent.getPortal().equals(portal.getId())) { |
|
147 |
throw new MismatchingContentException("["+portalType+ " - "+ pid+"] Conflicting page help content: portal id: "+pageHelpContent.getPortal()); |
|
148 |
} |
|
127 | 149 |
pageHelpContentDAO.delete(id); |
128 | 150 |
} |
129 | 151 |
return true; |
Also available in: Unified diff
[Trunk | Admin Tools Library]:
1. pom.xml: Added in dependency for spring security and and for uoa-authorization-library.
2. UoaAdminToolsLibraryApplication.java: import "AuthorizationConfiguration.class".
3. RolesUtils.java: Added folder handlers/utils and file handlers/utils/RolesUtils.java to get roles and info of user from authorization library.
4. AdminToolsLibraryExceptionsHandler.java: call setStatus of ExceptionResponse in handlers that status was not set | Use log.error instead of log.debug.
5. DivHelpContentService.java: Added checks and throw Exceptions in methods "deleteDivHelpContents()" and "toggleDivHelpContent()".
6. PageHelpContentService.java: Added checks and throw Exceptions in methods "deletePageHelpContents()" and "togglePageHelpContent()".
7. PortalService.java: Added checks and throw Exceptions in method "togglePage()".
8. EntityController.java: Added @PreAuthorize
Portal Admins: methods "insertEntity()" (/entity/save), "updateEntity()" (/entity/update), "deleteEntities()" (/entity/delete).
9. DivIdController.java: Added @PreAuthorize
Portal Admins: methods "insertDivId()" (/div/save), "updateDivId()" (/div/update), "deleteDivIds()" (/div/delete).
10. PageController.java: Added @PreAuthorize
Portal Admins: methods "insertPage()" (/page/save), "updatePage()" (/page/update), "deletePages()" (/page/delete).
11. AdminPortalRelationsController.java:
a. Added checks and throw Exceptions in methods "getEntitiesForCommunity()",
"getDivHelpContent()", "saveDivHelpContent()", "updateDivHelpContent()", "deleteDivHelpContents()", "toggleDivHelpContent()",
"togglePage()",
"getPageHelpContent()", "savePageHelpContent()", "updatePageHelpContent()", "deletePageHelpContents()", "togglePageHelpContent()"
b. Added @PreAuthorize
Portals Admin - Curators - Managers: "toggleEntity()" (/{portalType}/{pid}/entity/toggle),
"saveDivHelpContent()" (/{portalType}/{pid}/divhelpcontent/save), "updateDivHelpContent()" (/{portalType}/{pid}/divhelpcontent/update),
"deleteDivHelpContents()" (/{portalType}/{pid|/divhelpcontent/delete), "toggleDivHelpContent()" (/{portalType}/{pid|/divhelpcontent/toggle),
"togglePage()" (/{portalType}/{pid}/page/toggle),
"savePageHelpContent()" (/{portalType}/{pid}/pagehelpcontent/save), "updatePageHelpContent()" (/{portalType}/{pid}/pagehelpcontent/update),
"deletePageHelpContents()" (/{portalType}/{pid|/pagehelpcontent/delete), "togglePageHelpContent()" (/{portalType}/{pid|/pagehelpcontent/toggle)