[Admin Tools | Trunk]:

1. pom.xml: Increased version.
2. LayoutDAO.java & MongoDBLayoutDAO.java: Updated return type of "findByPortalPid()" to be List<Layout>.
3. LayoutService.java: Updated all usages of "findByPortalPid()" | In "save()" method, if there is one existing Layout for this pid already, set id to update layout instead of saving a new one.
4. CommunityController.java: Added method "deleteLayoutForCommunity()" (DELETE /community/{pid}/layout).
5. ConnectController.java: Added methods for "connect" and "default" pids: 
   "getLayoutForConnect()" (GET /connect/{pid}/layout - no authorization), "updateLayoutForConnect()" (POST /connect/{pid}/layout), "deleteLayoutForConnect()" (DELETE /connect/{pid}/layout).
This commit is contained in:
Konstantina Galouni 2022-08-09 09:44:39 +00:00
parent 99e01c7662
commit b5de59ee75
6 changed files with 87 additions and 26 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-admin-tools</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.4-SNAPSHOT</version>
<packaging>war</packaging>
<name>uoa-admin-tools</name>
<!-- Use parent with artifact spring-boot-starter-parent and add plugin with artifact spring-boot-maven-plugin in order to run springboot run command-->

View File

@ -159,5 +159,22 @@ public class CommunityController {
}
return layoutService.save(layout);
}
@PreAuthorize("hasAnyAuthority(" +
"@AuthorizationService.PORTAL_ADMIN, " +
"@AuthorizationService.curator('community'))")
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.DELETE)
public boolean deleteLayoutForCommunity(@PathVariable(value = "pid") String pid) {
Portal portal = portalService.getPortal(pid);
if(portal == null) {
// EXCEPTION - Entity Not Found
throw new ContentNotFoundException("CommunityController - Delete layout: Portal with pid: " + pid + " not found");
}
if(!portal.getType().equals("community")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("CommunityController - Delete layout: Portal with pid: "+pid+" has type: "+portal.getType()+" instead of community");
}
return layoutService.deleteByPid(pid);
}
}

View File

@ -1,5 +1,6 @@
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.PortalResponse;
@ -16,7 +17,6 @@ import java.util.List;
@RestController
@RequestMapping("/connect")
@CrossOrigin(origins = "*")
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
public class ConnectController {
private final Logger log = Logger.getLogger(this.getClass());
@ -26,6 +26,7 @@ public class ConnectController {
@Autowired
private PortalService portalService;
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/update", method = RequestMethod.POST)
public PortalResponse updateConnect(@RequestBody Portal portal) {
if (!portal.getType().equals("connect")) {
@ -44,6 +45,7 @@ public class ConnectController {
return portalResponse;
}
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/save", method = RequestMethod.POST)
public PortalResponse insertConnect(@RequestBody Portal portal) {
if (!portal.getType().equals("connect")) {
@ -55,6 +57,7 @@ public class ConnectController {
return portalResponse;
}
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public Boolean deleteConnect(@RequestBody List<String> portals) {
for (String id : portals) {
@ -75,15 +78,38 @@ public class ConnectController {
return true;
}
// @RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
// public Layout getLayoutForConnect(@PathVariable(value = "pid") String pid) {
// return layoutService.findByPid(pid);
// }
//
// @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
// @RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
// public Layout updateLayoutForConnect(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
// return layoutService.save(layout);
// }
// no authorization here, because it is called by server
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
public Layout getLayoutForConnect(@PathVariable(value = "pid") String pid) {
if(!pid.equals("connect") && !pid.equals("default")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("ConnectController - Get layout: Not accepted pid: "+pid);
}
return layoutService.findByPid(pid);
}
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
public Layout updateLayoutForConnect(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
if(!pid.equals("connect") && !pid.equals("default")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("ConnectController - Update layout: Not accepted pid: "+pid);
}
if(!pid.equals(layout.getPortalPid())) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("ConnectController - Update layout: Portal has pid: "+pid+" while layout has portalPid: "+layout.getPortalPid());
}
return layoutService.save(layout);
}
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.DELETE)
public boolean deleteLayoutForConnect(@PathVariable(value = "pid") String pid) {
if(!pid.equals("connect") && !pid.equals("default")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("ConnectController - Delete layout: Not accepted pid: "+pid);
}
return layoutService.deleteByPid(pid);
}
}

View File

@ -9,7 +9,7 @@ public interface LayoutDAO {
Layout findById(String Id);
Layout findByPortalPid(String portalPid);
List<Layout> findByPortalPid(String portalPid);
Layout save(Layout layout);

View File

@ -12,7 +12,7 @@ public interface MongoDBLayoutDAO extends LayoutDAO, MongoRepository<Layout, Str
Layout findById(String Id);
Layout findByPortalPid(String portalPid);
List<Layout> findByPortalPid(String portalPid);
Layout save(Layout layout);

View File

@ -2,6 +2,7 @@ package eu.dnetlib.uoaadmintools.services;
import eu.dnetlib.uoaadmintools.dao.LayoutDAO;
import eu.dnetlib.uoaadmintools.entities.Layout;
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -21,28 +22,45 @@ public class LayoutService {
public void updatePid(String old_pid, String new_pid) {
log.debug("layout service: updatePid");
Layout layout = layoutDAO.findByPortalPid(old_pid);
log.debug("layout service: layout id: "+(layout != null ? layout.getId() : "not found"));
if(layout != null) {
layout.setPortalPid(new_pid);
log.debug("layout layout: new layout pid: " + layout.getPortalPid());
layoutDAO.save(layout);
log.debug("layout saved!");
List<Layout> layouts = layoutDAO.findByPortalPid(old_pid);
for(Layout layout : layouts) {
log.debug("layout service: layout id: " + (layout != null ? layout.getId() : "not found"));
if (layout != null) {
layout.setPortalPid(new_pid);
log.debug("layout layout: new layout pid: " + layout.getPortalPid());
layoutDAO.save(layout);
log.debug("layout saved!");
}
}
}
public void deleteByPid(String pid) {
Layout layout = layoutDAO.findByPortalPid(pid);
if(layout != null) {
layoutDAO.delete(layout.getId());
public boolean deleteByPid(String pid) {
List<Layout> layouts = layoutDAO.findByPortalPid(pid);
for(Layout layout : layouts) {
if (layout != null) {
if(!pid.equals(layout.getPortalPid())) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("Delete layout by pid: Portal has pid: "+pid+" while layout has portalPid: "+layout.getPortalPid());
}
layoutDAO.delete(layout.getId());
}
}
return true;
}
public Layout findByPid(String pid) {
return layoutDAO.findByPortalPid(pid);
List<Layout> layouts = layoutDAO.findByPortalPid(pid);
if(layouts != null && layouts.size() > 0) {
return layouts.get(0);
}
return null;
}
public Layout save(Layout layout) {
List<Layout> oldLayouts = layoutDAO.findByPortalPid(layout.getPortalPid());
if(oldLayouts != null && oldLayouts.size() == 1) {
layout.setId(oldLayouts.get(0).getId()); // set existing id to update layout for this pid
}
return layoutDAO.save(layout);
}
}