Revision 60495
Added by Konstantina Galouni about 3 years ago
DivHelpContentService.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoaadmintoolslibrary.services; |
2 | 2 |
|
3 | 3 |
import eu.dnetlib.uoaadmintoolslibrary.dao.DivHelpContentDAO; |
4 |
import eu.dnetlib.uoaadmintoolslibrary.entities.DivHelpContent; |
|
5 |
import eu.dnetlib.uoaadmintoolslibrary.entities.DivId; |
|
6 |
import eu.dnetlib.uoaadmintoolslibrary.entities.Page; |
|
7 |
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; |
|
4 |
import eu.dnetlib.uoaadmintoolslibrary.entities.*; |
|
8 | 5 |
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.DivHelpContentResponse; |
9 | 6 |
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.DivIdResponse; |
10 | 7 |
|
8 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; |
|
9 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException; |
|
11 | 10 |
import org.apache.log4j.Logger; |
12 | 11 |
import org.springframework.beans.factory.annotation.Autowired; |
13 | 12 |
import org.springframework.stereotype.Service; |
... | ... | |
103 | 102 |
divHelpContentDAO.delete(id); |
104 | 103 |
} |
105 | 104 |
|
106 |
public Boolean deleteDivHelpContents(List<String> divHelpContents) throws Exception { |
|
105 |
public Boolean deleteDivHelpContents(List<String> divHelpContents, String pid, PortalType portalType) throws Exception { |
|
106 |
Portal portal = portalService.getPortal(pid); |
|
107 |
portalService.checkPortalInfo(pid, portalType.name(), portal, pid, "pid"); |
|
108 |
|
|
107 | 109 |
for (String id: divHelpContents) { |
110 |
DivHelpContent divHelpContent = getDivHelpContent(id); |
|
111 |
if(divHelpContent == null) { |
|
112 |
throw new ContentNotFoundException("Div help content with id: " + id + " not found"); |
|
113 |
} |
|
114 |
if(!divHelpContent.getPortal().equals(portal.getId())) { |
|
115 |
throw new MismatchingContentException("["+portalType+ " - "+ pid+"] Conflicting div help content: portal id: "+divHelpContent.getPortal()); |
|
116 |
} |
|
117 |
|
|
108 | 118 |
divHelpContentDAO.delete(id); |
109 | 119 |
} |
110 | 120 |
return true; |
111 | 121 |
} |
112 | 122 |
|
113 |
public List<String> toggleDivHelpContent(List<String> divHelpContents, String status) throws Exception { |
|
123 |
public List<String> toggleDivHelpContent(List<String> divHelpContents, String status, String pid, PortalType portalType) throws Exception { |
|
124 |
Portal portal = portalService.getPortal(pid); |
|
125 |
portalService.checkPortalInfo(pid, portalType.name(), portal, pid, "pid"); |
|
126 |
|
|
114 | 127 |
for (String id: divHelpContents) { |
115 | 128 |
log.debug("Id of divHelpContent: "+id); |
116 |
DivHelpContent divHelpContent = divHelpContentDAO.findById(id); |
|
129 |
DivHelpContent divHelpContent = getDivHelpContent(id); |
|
130 |
if(divHelpContent == null) { |
|
131 |
throw new ContentNotFoundException("Div help content with id: " + id + " not found"); |
|
132 |
} |
|
133 |
if(!divHelpContent.getPortal().equals(portal.getId())) { |
|
134 |
throw new MismatchingContentException("["+portalType+ " - "+ pid+"] Conflicting div help content: portal id: "+divHelpContent.getPortal()); |
|
135 |
} |
|
136 |
|
|
117 | 137 |
divHelpContent.setIsActive(Boolean.parseBoolean(status)); |
118 | 138 |
divHelpContentDAO.save(divHelpContent); |
119 | 139 |
} |
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)