[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:
parent
99e01c7662
commit
b5de59ee75
2
pom.xml
2
pom.xml
|
@ -4,7 +4,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>eu.dnetlib</groupId>
|
<groupId>eu.dnetlib</groupId>
|
||||||
<artifactId>uoa-admin-tools</artifactId>
|
<artifactId>uoa-admin-tools</artifactId>
|
||||||
<version>2.0.3-SNAPSHOT</version>
|
<version>2.0.4-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>uoa-admin-tools</name>
|
<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-->
|
<!-- Use parent with artifact spring-boot-starter-parent and add plugin with artifact spring-boot-maven-plugin in order to run springboot run command-->
|
||||||
|
|
|
@ -159,5 +159,22 @@ public class CommunityController {
|
||||||
}
|
}
|
||||||
return layoutService.save(layout);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.dnetlib.uoaadmintools.controllers;
|
package eu.dnetlib.uoaadmintools.controllers;
|
||||||
|
|
||||||
|
import eu.dnetlib.uoaadmintools.entities.Layout;
|
||||||
import eu.dnetlib.uoaadmintools.services.LayoutService;
|
import eu.dnetlib.uoaadmintools.services.LayoutService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
|
||||||
|
@ -16,7 +17,6 @@ import java.util.List;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/connect")
|
@RequestMapping("/connect")
|
||||||
@CrossOrigin(origins = "*")
|
@CrossOrigin(origins = "*")
|
||||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
|
||||||
public class ConnectController {
|
public class ConnectController {
|
||||||
private final Logger log = Logger.getLogger(this.getClass());
|
private final Logger log = Logger.getLogger(this.getClass());
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ public class ConnectController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private PortalService portalService;
|
private PortalService portalService;
|
||||||
|
|
||||||
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
||||||
public PortalResponse updateConnect(@RequestBody Portal portal) {
|
public PortalResponse updateConnect(@RequestBody Portal portal) {
|
||||||
if (!portal.getType().equals("connect")) {
|
if (!portal.getType().equals("connect")) {
|
||||||
|
@ -44,6 +45,7 @@ public class ConnectController {
|
||||||
return portalResponse;
|
return portalResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
||||||
public PortalResponse insertConnect(@RequestBody Portal portal) {
|
public PortalResponse insertConnect(@RequestBody Portal portal) {
|
||||||
if (!portal.getType().equals("connect")) {
|
if (!portal.getType().equals("connect")) {
|
||||||
|
@ -55,6 +57,7 @@ public class ConnectController {
|
||||||
return portalResponse;
|
return portalResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||||
public Boolean deleteConnect(@RequestBody List<String> portals) {
|
public Boolean deleteConnect(@RequestBody List<String> portals) {
|
||||||
for (String id : portals) {
|
for (String id : portals) {
|
||||||
|
@ -75,15 +78,38 @@ public class ConnectController {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
|
// no authorization here, because it is called by server
|
||||||
// public Layout getLayoutForConnect(@PathVariable(value = "pid") String pid) {
|
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
|
||||||
// return layoutService.findByPid(pid);
|
public Layout getLayoutForConnect(@PathVariable(value = "pid") String pid) {
|
||||||
// }
|
if(!pid.equals("connect") && !pid.equals("default")) {
|
||||||
//
|
// EXCEPTION - MismatchingContent
|
||||||
// @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
throw new MismatchingContentException("ConnectController - Get layout: Not accepted pid: "+pid);
|
||||||
// @RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
|
}
|
||||||
// public Layout updateLayoutForConnect(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
|
return layoutService.findByPid(pid);
|
||||||
// return layoutService.save(layout);
|
}
|
||||||
// }
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ public interface LayoutDAO {
|
||||||
|
|
||||||
Layout findById(String Id);
|
Layout findById(String Id);
|
||||||
|
|
||||||
Layout findByPortalPid(String portalPid);
|
List<Layout> findByPortalPid(String portalPid);
|
||||||
|
|
||||||
Layout save(Layout layout);
|
Layout save(Layout layout);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ public interface MongoDBLayoutDAO extends LayoutDAO, MongoRepository<Layout, Str
|
||||||
|
|
||||||
Layout findById(String Id);
|
Layout findById(String Id);
|
||||||
|
|
||||||
Layout findByPortalPid(String portalPid);
|
List<Layout> findByPortalPid(String portalPid);
|
||||||
|
|
||||||
Layout save(Layout layout);
|
Layout save(Layout layout);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package eu.dnetlib.uoaadmintools.services;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.LayoutDAO;
|
import eu.dnetlib.uoaadmintools.dao.LayoutDAO;
|
||||||
import eu.dnetlib.uoaadmintools.entities.Layout;
|
import eu.dnetlib.uoaadmintools.entities.Layout;
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -21,28 +22,45 @@ public class LayoutService {
|
||||||
|
|
||||||
public void updatePid(String old_pid, String new_pid) {
|
public void updatePid(String old_pid, String new_pid) {
|
||||||
log.debug("layout service: updatePid");
|
log.debug("layout service: updatePid");
|
||||||
Layout layout = layoutDAO.findByPortalPid(old_pid);
|
List<Layout> layouts = layoutDAO.findByPortalPid(old_pid);
|
||||||
log.debug("layout service: layout id: "+(layout != null ? layout.getId() : "not found"));
|
for(Layout layout : layouts) {
|
||||||
if(layout != null) {
|
log.debug("layout service: layout id: " + (layout != null ? layout.getId() : "not found"));
|
||||||
layout.setPortalPid(new_pid);
|
if (layout != null) {
|
||||||
log.debug("layout layout: new layout pid: " + layout.getPortalPid());
|
layout.setPortalPid(new_pid);
|
||||||
layoutDAO.save(layout);
|
log.debug("layout layout: new layout pid: " + layout.getPortalPid());
|
||||||
log.debug("layout saved!");
|
layoutDAO.save(layout);
|
||||||
|
log.debug("layout saved!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteByPid(String pid) {
|
public boolean deleteByPid(String pid) {
|
||||||
Layout layout = layoutDAO.findByPortalPid(pid);
|
List<Layout> layouts = layoutDAO.findByPortalPid(pid);
|
||||||
if(layout != null) {
|
for(Layout layout : layouts) {
|
||||||
layoutDAO.delete(layout.getId());
|
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) {
|
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) {
|
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);
|
return layoutDAO.save(layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue