[Trunk | Admin Tools]: Updated version of admin-tools-library | Updated structure of dynamic Menus.

1. pom.xml: Updated version of admin-tools-library to 1.0.5 (used to be 1.0.4).
2. Added Menu.java, MenuFull.java, MenuDAO.java, MongoDBMenuDAO.java.
3. CommunityController.java: On method "deleteCommunities()", delete also dynamic Menus for these pids.
4. Renamed MenuItemController.java to MenuController.java & added or updated methods to get/save/delete/toggle Menu structure instead of MenuItems.
5. Renamed MenuItemService.java to MenuService.java & added or updated methods to get/save/delete Menu structure instead of MenuItems.
6. MenuItem.java & MenuItemFull.java: Added field "String target;" (values _self or _blank) & field "Boolean isFeatured = false;".
7. UoaAdminToolsApplicationTests.java: Added test for sending email.
8. Layout.java: Added field "Date date".
This commit is contained in:
Konstantina Galouni 2022-07-27 12:52:33 +00:00
parent 834dcc26f0
commit a9cc44c443
13 changed files with 661 additions and 280 deletions

View File

@ -76,7 +76,7 @@
<dependency> <!-- this dependency includes dependency to uoa-authorization-library --> <dependency> <!-- this dependency includes dependency to uoa-authorization-library -->
<groupId>eu.dnetlib</groupId> <groupId>eu.dnetlib</groupId>
<artifactId>uoa-admin-tools-library</artifactId> <artifactId>uoa-admin-tools-library</artifactId>
<version>1.0.4</version> <version>1.0.5</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -1,17 +1,13 @@
package eu.dnetlib.uoaadmintools.controllers; package eu.dnetlib.uoaadmintools.controllers;
import eu.dnetlib.uoaadmintools.entities.Layout; import eu.dnetlib.uoaadmintools.entities.Layout;
import eu.dnetlib.uoaadmintools.services.LayoutService; import eu.dnetlib.uoaadmintools.services.*;
import eu.dnetlib.uoaadmintools.services.NotificationsService;
import eu.dnetlib.uoaadmintools.services.StatisticsService;
import eu.dnetlib.uoaadmintools.services.SubscriberService;
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;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException; import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService; import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
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.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
@ -40,6 +36,9 @@ public class CommunityController {
@Autowired @Autowired
private SubscriberService subscriberService; private SubscriberService subscriberService;
@Autowired
private MenuService menuService;
@Autowired @Autowired
private PortalService portalService; private PortalService portalService;
@ -95,7 +94,7 @@ public class CommunityController {
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/delete", method = RequestMethod.POST) @RequestMapping(value = "/delete", method = RequestMethod.POST)
public Boolean deleteCommunities(@RequestBody List<String> portals) { public Boolean deleteCommunities(@RequestBody List<String> portals) throws Exception {
List<String> roles = rolesUtils.getRoles(); List<String> roles = rolesUtils.getRoles();
for (String id: portals) { for (String id: portals) {
@ -115,6 +114,7 @@ public class CommunityController {
subscriberService.deletePortalSubscribers(pid); subscriberService.deletePortalSubscribers(pid);
layoutService.deleteByPid(pid); layoutService.deleteByPid(pid);
notificationsService.deleteByPid(pid); notificationsService.deleteByPid(pid);
menuService.deleteMenuByPortalPid(pid);
} }
return true; return true;

View File

@ -1,13 +1,12 @@
package eu.dnetlib.uoaadmintools.controllers; package eu.dnetlib.uoaadmintools.controllers;
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO; import eu.dnetlib.uoaadmintools.entities.menu.Menu;
import eu.dnetlib.uoaadmintools.entities.Notifications; import eu.dnetlib.uoaadmintools.entities.menu.MenuFull;
import eu.dnetlib.uoaadmintools.entities.menu.MenuItem; import eu.dnetlib.uoaadmintools.entities.menu.MenuItem;
import eu.dnetlib.uoaadmintools.entities.menu.MenuItemFull; import eu.dnetlib.uoaadmintools.entities.menu.MenuItemFull;
import eu.dnetlib.uoaadmintools.services.MenuItemService; import eu.dnetlib.uoaadmintools.services.MenuService;
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO; import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalPage;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException; import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
@ -20,55 +19,40 @@ import java.util.List;
@RestController @RestController
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
public class MenuItemController { public class MenuController {
private final Logger log = Logger.getLogger(this.getClass()); private final Logger log = Logger.getLogger(this.getClass());
@Autowired @Autowired
private MenuItemService menuItemService; private MenuService menuService;
@Autowired @Autowired
private PortalDAO portalDAO; private PortalDAO portalDAO;
@Autowired @Autowired
private RolesUtils rolesUtils; private RolesUtils rolesUtils;
// @PreAuthorize("hasAnyAuthority(" + // NOT USED - maybe leave it
// "@AuthorizationService.PORTAL_ADMIN, " + //// @PreAuthorize("hasAnyAuthority(" +
// "@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))") //// "@AuthorizationService.PORTAL_ADMIN, " +
@RequestMapping(value = "/community/{pid}/menu", method = RequestMethod.GET) //// "@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
public List<MenuItem> getMenuItems(@PathVariable(value = "pid") String pid ) throws ContentNotFoundException { // @RequestMapping(value = "/community/{pid}/menu", method = RequestMethod.GET)
Portal portal = portalDAO.findByPid(pid); // public List<MenuItem> getMenuItems(@PathVariable(value = "pid") String pid ) throws ContentNotFoundException {
if(portal == null){ // // @RequestParam(value="featured", required=false) String isFeatured
throw new ContentNotFoundException("Portal with pid: "+pid+" not found"); // Portal portal = portalDAO.findByPid(pid);
} // if(portal == null){
if(!portal.getType().equals("community")) { // throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
// EXCEPTION - MismatchingContent // }
throw new MismatchingContentException("Get Notifications: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community"); // if(!portal.getType().equals("community")) {
} // // EXCEPTION - MismatchingContent
// throw new MismatchingContentException("Get Notifications: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
List<MenuItem> menuItems = menuItemService.getMenuItems(pid); // }
if(menuItems == null || menuItems.size() == 0){ //
throw new ContentNotFoundException("Menu for community with pid: "+pid+" not found"); // List<MenuItem> menuItems = menuService.getMenuItems(pid);
} // if(menuItems == null || menuItems.size() == 0){
return menuItems; // throw new ContentNotFoundException("Menu for community with pid: "+pid+" not found");
} // }
// return menuItems;
@RequestMapping(value = "/community/{pid}/menu/{itemId}/full", method = RequestMethod.GET) // }
public MenuItemFull getMenuItemFull(@PathVariable(value = "pid") String pid, @PathVariable(value = "itemId") String itemId ) throws ContentNotFoundException {
Portal portal = portalDAO.findByPid(pid);
if(portal == null){
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
}
if(!portal.getType().equals("community")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("Get Menu Item Full: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
}
MenuItemFull menuItem = menuItemService.getMenuItemFull(itemId);
if(menuItem == null){
throw new ContentNotFoundException("MenuItem with id: "+itemId+" for community with pid: "+pid+" not found");
}
return menuItem;
}
// OLD endpoint
@RequestMapping(value = "/community/{pid}/menu/root/full", method = RequestMethod.GET) @RequestMapping(value = "/community/{pid}/menu/root/full", method = RequestMethod.GET)
public List<MenuItemFull> getRootMenuItemsFull(@PathVariable(value = "pid") String pid ) throws ContentNotFoundException { public List<MenuItemFull> getRootMenuItemsFull(@PathVariable(value = "pid") String pid ) throws ContentNotFoundException {
Portal portal = portalDAO.findByPid(pid); Portal portal = portalDAO.findByPid(pid);
@ -80,15 +64,15 @@ public class MenuItemController {
throw new MismatchingContentException("getMenuItemsFull: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community"); throw new MismatchingContentException("getMenuItemsFull: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
} }
List<MenuItemFull> menuItems = menuItemService.getRootMenuItemsFull(pid); List<MenuItemFull> menuItems = menuService.getRootMenuItemsFull(pid);
// if(menuItems == null || menuItems.size() == 0){ // if(menuItems == null || menuItems.size() == 0){
// throw new ContentNotFoundException("Root menu for community with pid: "+pid+" not found"); // throw new ContentNotFoundException("Root menu for community with pid: "+pid+" not found");
// } // }
return menuItems; return menuItems;
} }
@RequestMapping(value = "/community/{pid}/menu/root", method = RequestMethod.GET) @RequestMapping(value = "/community/{pid}/menu/full", method = RequestMethod.GET)
public List<MenuItem> getRootMenuItems(@PathVariable(value = "pid") String pid ) throws ContentNotFoundException { public MenuFull getMenuFull(@PathVariable(value = "pid") String pid ) throws ContentNotFoundException {
Portal portal = portalDAO.findByPid(pid); Portal portal = portalDAO.findByPid(pid);
if(portal == null){ if(portal == null){
throw new ContentNotFoundException("Portal with pid: "+pid+" not found"); throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
@ -98,29 +82,8 @@ public class MenuItemController {
throw new MismatchingContentException("getMenuItemsFull: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community"); throw new MismatchingContentException("getMenuItemsFull: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
} }
List<MenuItem> menuItems = menuItemService.getMenuItemsByParent(null, pid); MenuFull menu = menuService.getMenuFull(pid);
if(menuItems == null || menuItems.size() == 0){ return menu;
throw new ContentNotFoundException("Root menu for community with pid: "+pid+" not found");
}
return menuItems;
}
@RequestMapping(value = "/community/{pid}/menu/{parentId}/children", method = RequestMethod.GET)
public List<MenuItem> getChildrenMenuItemsOfParent(@PathVariable(value = "pid") String pid, @PathVariable(value="parentId") String parentId) throws ContentNotFoundException {
Portal portal = portalDAO.findByPid(pid);
if(portal == null){
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
}
if(!portal.getType().equals("community")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("getMenuItemsFull: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
}
List<MenuItem> menuItems = menuItemService.getMenuItemsByParent(parentId, pid);
if(menuItems == null || menuItems.size() == 0){
throw new ContentNotFoundException("Root menu for community with pid: "+pid+" not found");
}
return menuItems;
} }
@PreAuthorize("hasAnyAuthority(" + @PreAuthorize("hasAnyAuthority(" +
@ -137,6 +100,10 @@ public class MenuItemController {
// EXCEPTION - MismatchingContent // EXCEPTION - MismatchingContent
throw new MismatchingContentException("updateMenuItem: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community"); throw new MismatchingContentException("updateMenuItem: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
} }
if(menuItemFull.getIsFeatured() && menuItemFull.getItems() != null && menuItemFull.getItems().size() > 0) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("updateMenuItem: MenuItem "+menuItemFull.getId()+" cannot be featured because it has "+menuItemFull.getItems().size() + " sub menu items");
}
if(menuItemFull.getType() == null || if(menuItemFull.getType() == null ||
(menuItemFull.getType().equals("internal") && menuItemFull.getRoute() == null) || (menuItemFull.getType().equals("internal") && menuItemFull.getRoute() == null) ||
(menuItemFull.getType().equals("external") && menuItemFull.getUrl() == null)) { (menuItemFull.getType().equals("external") && menuItemFull.getUrl() == null)) {
@ -155,7 +122,7 @@ public class MenuItemController {
throw new MismatchingContentException("updateMenuItem: This MenuItem has no id."); throw new MismatchingContentException("updateMenuItem: This MenuItem has no id.");
} }
return menuItemService.updateMenuItem(menuItemFull); return menuService.updateMenu(menuItemFull, pid);
} }
@PreAuthorize("hasAnyAuthority(" + @PreAuthorize("hasAnyAuthority(" +
@ -172,6 +139,10 @@ public class MenuItemController {
// EXCEPTION - MismatchingContent // EXCEPTION - MismatchingContent
throw new MismatchingContentException("insertMenuItem: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community"); throw new MismatchingContentException("insertMenuItem: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
} }
if(menuItem.getIsFeatured() && menuItem.getItems() != null && menuItem.getItems().size() > 0) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("updateMenuItem: MenuItem "+menuItem.getId()+" cannot be featured because it has "+menuItem.getItems().size() + " sub menu items");
}
if(menuItem.getType() == null || if(menuItem.getType() == null ||
(menuItem.getType().equals("internal") && menuItem.getRoute() == null) || (menuItem.getType().equals("internal") && menuItem.getRoute() == null) ||
(menuItem.getType().equals("external") && menuItem.getUrl() == null)) { (menuItem.getType().equals("external") && menuItem.getUrl() == null)) {
@ -190,7 +161,7 @@ public class MenuItemController {
throw new MismatchingContentException("insertMenuItem: MenuItem has already an id: "+menuItem.getId()); throw new MismatchingContentException("insertMenuItem: MenuItem has already an id: "+menuItem.getId());
} }
return menuItemService.insertMenuItem(menuItem, pid); return menuService.insertMenuItemInMenu(menuItem, pid);
} }
@PreAuthorize("hasAnyAuthority(" + @PreAuthorize("hasAnyAuthority(" +
@ -205,9 +176,36 @@ public class MenuItemController {
} }
if(!portal.getType().equals("community")) { if(!portal.getType().equals("community")) {
// EXCEPTION - MismatchingContent // EXCEPTION - MismatchingContent
throw new MismatchingContentException("Get Notifications: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community"); throw new MismatchingContentException("deleteMenuItem: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
} }
return menuItemService.deleteMenuItem(menuItemId, pid); return menuService.deleteMenuItem(menuItemId, pid);
}
@PreAuthorize("hasAnyAuthority(" +
"@AuthorizationService.PORTAL_ADMIN, " +
"@AuthorizationService.curator('community')," +
"@AuthorizationService.manager('community', #pid))")
@RequestMapping(value = "/community/{pid}/menu/reorder", method = RequestMethod.POST)
public Boolean reorderMenuItems(@PathVariable String pid, @RequestBody List<MenuItemFull> menuItems) throws Exception {
Portal portal = portalDAO.findByPid(pid);
if(portal == null){
throw new ContentNotFoundException("Portal with pid: "+pid+" not found");
}
if(!portal.getType().equals("community")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("reorderMenuItems: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community");
}
return menuService.reorderMenuItems(menuItems, pid);
}
@PreAuthorize("hasAnyAuthority(" +
"@AuthorizationService.PORTAL_ADMIN, " +
"@AuthorizationService.curator('community')," +
"@AuthorizationService.manager('community', #pid))")
@RequestMapping(value = {"/community/{pid}/menu/toggle"}, method = RequestMethod.POST)
public Menu toggleMenu(@PathVariable(value = "pid") String pid, @RequestParam String status, @RequestParam(value="featured", required=false) String isFeatured) throws Exception {
return menuService.toggleMenu(pid, status, isFeatured);
} }
} }

View File

@ -0,0 +1,16 @@
package eu.dnetlib.uoaadmintools.dao;
import eu.dnetlib.uoaadmintools.entities.menu.Menu;
import eu.dnetlib.uoaadmintools.entities.menu.MenuItem;
import java.util.List;
public interface MenuDAO {
List<Menu> findAll();
Menu findByPortalPid(String portalPid);
Menu save(Menu menu);
void deleteAll();
void deleteByPortalPid(String portalPid);
}

View File

@ -0,0 +1,17 @@
package eu.dnetlib.uoaadmintools.dao.MongoDBDAOs;
import eu.dnetlib.uoaadmintools.dao.MenuDAO;
import eu.dnetlib.uoaadmintools.entities.menu.Menu;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
public interface MongoDBMenuDAO extends MenuDAO, MongoRepository<Menu, String> {
List<Menu> findAll();
Menu findByPortalPid(String portalPid);
Menu save(Menu menu);
void deleteAll();
void deleteByPortalPid(String portalPid);
}

View File

@ -7,6 +7,8 @@ import eu.dnetlib.uoaadmintools.entities.layoutEntities.Links;
import eu.dnetlib.uoaadmintools.entities.layoutEntities.Panel; import eu.dnetlib.uoaadmintools.entities.layoutEntities.Panel;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import java.util.Date;
public class Layout { public class Layout {
@Id @Id
@ -14,6 +16,7 @@ public class Layout {
private String id; private String id;
private String portalPid; private String portalPid;
private Object layoutOptions; private Object layoutOptions;
private Date date ;
public Layout() { } public Layout() { }
@ -40,4 +43,12 @@ public class Layout {
public void setLayoutOptions(Object layoutOptions) { public void setLayoutOptions(Object layoutOptions) {
this.layoutOptions = layoutOptions; this.layoutOptions = layoutOptions;
} }
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
} }

View File

@ -0,0 +1,65 @@
package eu.dnetlib.uoaadmintools.entities.menu;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.data.annotation.Id;
import java.util.ArrayList;
import java.util.List;
public class Menu {
@Id
@JsonProperty("portalPid")
String portalPid;
public boolean isFeaturedMenuEnabled;
public boolean isMenuEnabled;
public List<String> featuredMenuItems;
public List<String> menuItems;
public Menu(String portalPid) {
this.setPortalPid(portalPid);
this.setMenuEnabled(true);
this.setFeaturedMenuEnabled(true);
this.setMenuItems(new ArrayList<>());
this.setFeaturedMenuItems(new ArrayList<>());
}
public String getPortalPid() {
return portalPid;
}
public void setPortalPid(String portalPid) {
this.portalPid = portalPid;
}
public boolean getIsFeaturedMenuEnabled() {
return isFeaturedMenuEnabled;
}
public void setFeaturedMenuEnabled(boolean featuredMenuEnabled) {
isFeaturedMenuEnabled = featuredMenuEnabled;
}
public boolean getIsMenuEnabled() {
return isMenuEnabled;
}
public void setMenuEnabled(boolean menuEnabled) {
isMenuEnabled = menuEnabled;
}
public List<String> getFeaturedMenuItems() {
return featuredMenuItems;
}
public void setFeaturedMenuItems(List<String> featuredMenuItems) {
this.featuredMenuItems = featuredMenuItems;
}
public List<String> getMenuItems() {
return menuItems;
}
public void setMenuItems(List<String> menuItems) {
this.menuItems = menuItems;
}
}

View File

@ -0,0 +1,51 @@
package eu.dnetlib.uoaadmintools.entities.menu;
import java.util.List;
public class MenuFull {
String portalPid;
public boolean isFeaturedMenuEnabled;
public boolean isMenuEnabled;
public List<MenuItemFull> featuredMenuItems;
public List<MenuItemFull> menuItems;
public String getPortalPid() {
return portalPid;
}
public void setPortalPid(String portalPid) {
this.portalPid = portalPid;
}
public boolean getIsFeaturedMenuEnabled() {
return isFeaturedMenuEnabled;
}
public void setFeaturedMenuEnabled(boolean featuredMenuEnabled) {
isFeaturedMenuEnabled = featuredMenuEnabled;
}
public boolean getIsMenuEnabled() {
return isMenuEnabled;
}
public void setMenuEnabled(boolean menuEnabled) {
isMenuEnabled = menuEnabled;
}
public List<MenuItemFull> getFeaturedMenuItems() {
return featuredMenuItems;
}
public void setFeaturedMenuItems(List<MenuItemFull> featuredMenuItems) {
this.featuredMenuItems = featuredMenuItems;
}
public List<MenuItemFull> getMenuItems() {
return menuItems;
}
public void setMenuItems(List<MenuItemFull> menuItems) {
this.menuItems = menuItems;
}
}

View File

@ -13,10 +13,12 @@ public class MenuItem {
String title; String title;
String url; // external url String url; // external url
String route; // internal url - using angular routing and components String route; // internal url - using angular routing and components
String type; // internal or external String type; // internal or external or noAction
String target; // _self or _blank
List<String> items; List<String> items;
String parentItemId; String parentItemId;
String portalPid; String portalPid;
Boolean isFeatured = false;
public MenuItem(){ public MenuItem(){
@ -62,6 +64,14 @@ public class MenuItem {
this.type = type; this.type = type;
} }
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public List<String> getItems() { public List<String> getItems() {
return items; return items;
} }
@ -86,6 +96,14 @@ public class MenuItem {
this.portalPid = portalPid; this.portalPid = portalPid;
} }
public Boolean getIsFeatured() {
return isFeatured;
}
public void setIsFeatured(Boolean isFeatured) {
this.isFeatured = isFeatured;
}
@Override @Override
public String toString() { public String toString() {
return "MenuItem{" + return "MenuItem{" +

View File

@ -13,10 +13,12 @@ public class MenuItemFull {
String title; String title;
String url; // external url String url; // external url
String route; // internal url - using angular routing and components String route; // internal url - using angular routing and components
String type; // internal or external String type; // internal or external or noAction
String target; // _self or _blank
List<MenuItemFull> items; List<MenuItemFull> items;
String parentItemId; String parentItemId;
String portalPid; String portalPid;
Boolean isFeatured = false;
public MenuItemFull(){} public MenuItemFull(){}
public MenuItemFull(MenuItem menuItem){ public MenuItemFull(MenuItem menuItem){
@ -24,9 +26,11 @@ public class MenuItemFull {
setTitle(menuItem.getTitle()); setTitle(menuItem.getTitle());
setUrl(menuItem.getUrl()); setUrl(menuItem.getUrl());
setType(menuItem.getType()); setType(menuItem.getType());
setTarget(menuItem.getTarget());
setRoute(menuItem.getRoute()); setRoute(menuItem.getRoute());
setParentItemId(menuItem.getParentItemId()); setParentItemId(menuItem.getParentItemId());
setPortalPid(menuItem.getPortalPid()); setPortalPid(menuItem.getPortalPid());
setIsFeatured(menuItem.getIsFeatured());
} }
public String getId() { public String getId() {
@ -70,6 +74,14 @@ public class MenuItemFull {
this.type = type; this.type = type;
} }
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public List<MenuItemFull> getItems() { public List<MenuItemFull> getItems() {
return items; return items;
} }
@ -94,6 +106,14 @@ public class MenuItemFull {
this.portalPid = portalPid; this.portalPid = portalPid;
} }
public Boolean getIsFeatured() {
return isFeatured;
}
public void setIsFeatured(Boolean isFeatured) {
this.isFeatured = isFeatured;
}
@Override @Override
public String toString() { public String toString() {
return "MenuItemFull{" + return "MenuItemFull{" +

View File

@ -1,197 +0,0 @@
package eu.dnetlib.uoaadmintools.services;
import eu.dnetlib.uoaadmintools.dao.MenuItemDAO;
import eu.dnetlib.uoaadmintools.entities.menu.MenuItem;
import eu.dnetlib.uoaadmintools.entities.menu.MenuItemFull;
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class MenuItemService {
private final Logger log = Logger.getLogger(this.getClass());
@Autowired
private MenuItemDAO menuItemDAO;
public MenuItem getMenuItem(String id) {
return menuItemDAO.findById(id);
}
public MenuItemFull getMenuItemFull(String id) {
return this.getMenuItemFull(id, 1);
}
public MenuItemFull getMenuItemFull(String id, int maxDepth) {
MenuItem menuItem = menuItemDAO.findById(id);
MenuItemFull menuItemFull = new MenuItemFull(menuItem);
if(maxDepth == 0) {
menuItemFull.setItems(new ArrayList<>());
return menuItemFull;
}
List<MenuItemFull> menuItemsFull = new ArrayList<>();
for(String menuItemString : menuItem.getItems()) {
menuItemsFull.add(this.getMenuItemFull(menuItemString, maxDepth-1));
}
menuItemFull.setItems(menuItemsFull);
return menuItemFull;
}
public List<MenuItem> getMenuItems(String portalPid) {
if(portalPid != null) {
return menuItemDAO.findByPortalPid(portalPid);
} else {
return menuItemDAO.findAll();
}
}
public List<MenuItem> getMenuItemsByParent(String parentId, String portalPid) {
if(portalPid != null) {
return menuItemDAO.findByParentItemIdAndPortalPid(parentId, portalPid);
} else {
return menuItemDAO.findByParentItemId(parentId);
}
}
public List<MenuItemFull> getRootMenuItemsFull(String portalPid) {
List<MenuItem> rootMenuItems = this.getMenuItemsByParent(null, portalPid);
List<MenuItemFull> rootMenuItemsFull = new ArrayList<>();
for(MenuItem rootMenuItem : rootMenuItems) {
MenuItemFull rootMenuItemFull = new MenuItemFull(rootMenuItem);
List<MenuItemFull> childrenMenuItemsFull = new ArrayList<>();
for(String childMenuItemString : rootMenuItem.getItems()) {
childrenMenuItemsFull.add(this.getMenuItemFull(childMenuItemString));
}
rootMenuItemFull.setItems(childrenMenuItemsFull);
rootMenuItemsFull.add(rootMenuItemFull);
}
return rootMenuItemsFull;
}
// public MenuItemFull saveAndReturn(MenuItemFull menuItemFull) {
// menuItemFull.setId(save(menuItemFull));
// return menuItemFull;
// }
public MenuItemFull insertMenuItem(MenuItem menuItem, String portalPid) {
// for(MenuItemFull childMenuItemFull : menuItemFull.getItems()) {
// childMenuItemFull.setId(this.save(childMenuItemFull));
// }
// MenuItem menuItem = getMenuItemByMenuItemFull(menuItemFull);
// menuItemDAO.save(menuItem);
//
// return menuItem.getId();
MenuItem parent = null;
if(menuItem.getParentItemId() != null && !menuItem.getParentItemId().equals("")) {
parent = getMenuItem(menuItem.getParentItemId());
if (!parent.getPortalPid().equals(portalPid)) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("insertMenuItem: parent ("+parent.getParentItemId()+") of MenuItem has portalPid: " + parent.getPortalPid() + " instead of " + portalPid);
}
} else {
menuItem.setParentItemId(null);
}
// MenuItem menuItem = getMenuItemByMenuItemFull(menuItemFull);
if(menuItem.getItems() == null) {
List<String> menuItems = new ArrayList<String>();
menuItem.setItems(menuItems);
}
menuItemDAO.save(menuItem);
if(parent != null) {
List<String> siblingsOfNew = parent.getItems();
siblingsOfNew.add(menuItem.getId());
parent.setItems(siblingsOfNew);
menuItemDAO.save(parent);
}
MenuItemFull menuItemFull = new MenuItemFull(menuItem);
menuItemFull.setItems(new ArrayList<>());
return menuItemFull;
}
public MenuItemFull updateMenuItem(MenuItemFull menuItemFull) {
MenuItem menuItem = getMenuItemByMenuItemFull(menuItemFull);
// Update should not affect parent or children - only basic info can be updated
MenuItem oldMenuItem = getMenuItem(menuItemFull.getId());
menuItem.setItems(oldMenuItem.getItems());
menuItem.setParentItemId(oldMenuItem.getParentItemId());
menuItemDAO.save(menuItem);
menuItemFull = getMenuItemFull(menuItem.getId());
return menuItemFull;
}
public Boolean deleteMenuItem(String id, String portalPid) throws Exception {
// menuItemDAO.delete(id);
log.debug("delete menu item; "+id);
List<String> menuItems = new ArrayList<>();
menuItems.add(id);
return deleteMenuItems(menuItems, portalPid);
}
public Boolean deleteMenuItems(List<String> menuItems, String portalPid) throws Exception {
if(menuItems == null) {
return true;
}
for (String id: menuItems) {
MenuItem menuItem = menuItemDAO.findById(id);
if(!portalPid.equals(menuItem.getPortalPid())) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("Delete Menu Items: MenuItem with id: "+id+" has portalPid: "+menuItem.getPortalPid()+" instead of "+portalPid);
}
deleteMenuItems(menuItem.getItems(), portalPid);
if(menuItem.getParentItemId() != null && !menuItem.getParentItemId().equals("")) {
MenuItem parent = menuItemDAO.findById(menuItem.getParentItemId());
List<String> siblingsOfDeleted = parent.getItems();
siblingsOfDeleted.remove(id);
parent.setItems(siblingsOfDeleted);
menuItemDAO.save(parent);
}
menuItemDAO.delete(id);
}
return true;
}
private MenuItem getMenuItemByMenuItemFull(MenuItemFull menuItemFull) {
MenuItem menuItem = new MenuItem();
menuItem.setId(menuItemFull.getId());
menuItem.setTitle(menuItemFull.getTitle());
menuItem.setUrl(menuItemFull.getUrl());
menuItem.setType(menuItemFull.getType());
menuItem.setRoute(menuItemFull.getRoute());
menuItem.setPortalPid(menuItemFull.getPortalPid());
menuItem.setParentItemId(menuItemFull.getParentItemId());
List<MenuItemFull> menuItemsFull = menuItemFull.getItems();
List<String> menuItems = new ArrayList<String>();
if(menuItemsFull != null) {
for (MenuItemFull childMenuItemFull : menuItemsFull) {
menuItems.add(childMenuItemFull.getId());
}
}
menuItem.setItems(menuItems);
return menuItem;
}
}

View File

@ -0,0 +1,368 @@
package eu.dnetlib.uoaadmintools.services;
import eu.dnetlib.uoaadmintools.dao.MenuDAO;
import eu.dnetlib.uoaadmintools.dao.MenuItemDAO;
import eu.dnetlib.uoaadmintools.entities.menu.Menu;
import eu.dnetlib.uoaadmintools.entities.menu.MenuFull;
import eu.dnetlib.uoaadmintools.entities.menu.MenuItem;
import eu.dnetlib.uoaadmintools.entities.menu.MenuItemFull;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class MenuService {
private final Logger log = Logger.getLogger(this.getClass());
@Autowired
private MenuDAO menuDAO;
@Autowired
private MenuItemDAO menuItemDAO;
public MenuItem getMenuItem(String id) {
return menuItemDAO.findById(id);
}
public MenuItemFull getMenuItemFull(String id) {
return this.getMenuItemFull(id, 1);
}
public MenuItemFull getMenuItemFull(String id, int maxDepth) {
MenuItem menuItem = menuItemDAO.findById(id);
MenuItemFull menuItemFull = new MenuItemFull(menuItem);
if(maxDepth == 0) {
menuItemFull.setItems(new ArrayList<>());
return menuItemFull;
}
List<MenuItemFull> menuItemsFull = new ArrayList<>();
for(String menuItemString : menuItem.getItems()) {
menuItemsFull.add(this.getMenuItemFull(menuItemString, maxDepth-1));
}
menuItemFull.setItems(menuItemsFull);
return menuItemFull;
}
public List<MenuItem> getMenuItemsByParent(String parentId, String portalPid) {
if(portalPid != null) {
return menuItemDAO.findByParentItemIdAndPortalPid(parentId, portalPid);
} else {
return menuItemDAO.findByParentItemId(parentId);
}
}
public List<MenuItemFull> getRootMenuItemsFull(String portalPid) {
List<MenuItem> rootMenuItems = this.getMenuItemsByParent(null, portalPid);
List<MenuItemFull> rootMenuItemsFull = new ArrayList<>();
for(MenuItem rootMenuItem : rootMenuItems) {
MenuItemFull rootMenuItemFull = new MenuItemFull(rootMenuItem);
List<MenuItemFull> childrenMenuItemsFull = new ArrayList<>();
for(String childMenuItemString : rootMenuItem.getItems()) {
childrenMenuItemsFull.add(this.getMenuItemFull(childMenuItemString));
}
rootMenuItemFull.setItems(childrenMenuItemsFull);
rootMenuItemsFull.add(rootMenuItemFull);
}
return rootMenuItemsFull;
}
public MenuFull getMenuFull(String portalPid) {
MenuFull menuFull = new MenuFull();
Menu menu = menuDAO.findByPortalPid(portalPid);
List<MenuItemFull> featuredMenuItems = new ArrayList<>();
List<MenuItemFull> menuItems = new ArrayList<>();
if(menu == null) {
menuFull.setFeaturedMenuEnabled(true);
menuFull.setMenuEnabled(true);
} else {
for (String menuItemId : menu.getFeaturedMenuItems()) {
featuredMenuItems.add(getFullRootMenuItemById(menuItemId, portalPid, true));
}
for (String menuItemId : menu.getMenuItems()) {
menuItems.add(getFullRootMenuItemById(menuItemId, portalPid, false));
}
menuFull.setFeaturedMenuEnabled(menu.getIsFeaturedMenuEnabled());
menuFull.setMenuEnabled(menu.getIsMenuEnabled());
}
menuFull.setPortalPid(portalPid);
menuFull.setFeaturedMenuItems(featuredMenuItems);
menuFull.setMenuItems(menuItems);
return menuFull;
}
private MenuItemFull getFullRootMenuItemById(String menuItemId, String portalPid, Boolean isFeatured) {
MenuItem rootMenuItem = menuItemDAO.findById(menuItemId);
if(rootMenuItem.getIsFeatured() != isFeatured) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("getFullRootMenuItemById: Menu item should "+(isFeatured ? "" : "not ")+"be featured");
}
if(!rootMenuItem.getPortalPid().equals(portalPid)) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("getFullRootMenuItemById: Menu item with id: "+rootMenuItem.getId()+" has portal pid: "+rootMenuItem.getPortalPid()+" instead of "+portalPid);
}
if(rootMenuItem.getParentItemId() != null) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("getFullRootMenuItemById: Menu item should be root (no parentId), but instead parentId: "+rootMenuItem.getParentItemId());
}
MenuItemFull rootMenuItemFull = new MenuItemFull(rootMenuItem);
List<MenuItemFull> childrenMenuItemsFull = new ArrayList<>();
for(String childMenuItemString : rootMenuItem.getItems()) {
childrenMenuItemsFull.add(this.getMenuItemFull(childMenuItemString));
}
rootMenuItemFull.setItems(childrenMenuItemsFull);
return rootMenuItemFull;
}
private MenuItemFull insertMenuItem(MenuItem menuItem, String portalPid) {
MenuItem parent = null;
if(menuItem.getParentItemId() != null && !menuItem.getParentItemId().equals("")) {
parent = getMenuItem(menuItem.getParentItemId());
if (!parent.getPortalPid().equals(portalPid)) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("insertMenuItem: parent ("+parent.getParentItemId()+") of MenuItem has portalPid: " + parent.getPortalPid() + " instead of " + portalPid);
}
} else {
menuItem.setParentItemId(null);
}
if(menuItem.getItems() == null) {
List<String> menuItems = new ArrayList<String>();
menuItem.setItems(menuItems);
}
menuItemDAO.save(menuItem);
if(parent != null) {
List<String> siblingsOfNew = parent.getItems();
siblingsOfNew.add(menuItem.getId());
parent.setItems(siblingsOfNew);
menuItemDAO.save(parent);
}
MenuItemFull menuItemFull = new MenuItemFull(menuItem);
menuItemFull.setItems(new ArrayList<>());
return menuItemFull;
}
public MenuItemFull insertMenuItemInMenu(MenuItem menuItem, String portalPid) {
MenuItemFull menuItemFull = insertMenuItem(menuItem, portalPid);
Menu menu = menuDAO.findByPortalPid(portalPid);
if(menu == null) {
menu = new Menu(portalPid);
}
if(menuItem.getIsFeatured() && menuItem.getParentItemId() == null) {
menu.getFeaturedMenuItems().add(menuItemFull.getId());
} else if(menuItem.getParentItemId() == null) {
menu.getMenuItems().add(menuItemFull.getId());
}
menuDAO.save(menu);
return menuItemFull;
}
public MenuItemFull updateMenuItem(MenuItemFull menuItemFull) {
MenuItem menuItem = getMenuItemByMenuItemFull(menuItemFull);
// Update should not affect parent or children - only basic info can be updated
MenuItem oldMenuItem = getMenuItem(menuItemFull.getId());
menuItem.setItems(oldMenuItem.getItems());
menuItem.setParentItemId(oldMenuItem.getParentItemId());
menuItemDAO.save(menuItem);
menuItemFull = getMenuItemFull(menuItem.getId());
return menuItemFull;
}
public MenuItemFull updateMenu(MenuItemFull menuItemFull, String portalPid) {
menuItemFull = updateMenuItem(menuItemFull);
Menu menu = menuDAO.findByPortalPid(portalPid);
if(menu == null) {
// EXCEPTION - ContentNotFoundException
throw new ContentNotFoundException("updateMenu: No Menu found for portal pid: "+portalPid);
}
List<String> featuredMenuItems = menu.getFeaturedMenuItems();
List<String> menuItems = menu.getMenuItems();
if (menuItemFull.getIsFeatured() && menuItemFull.getParentItemId() == null && !featuredMenuItems.contains(menuItemFull.getId())) {
featuredMenuItems.add(menuItemFull.getId());
} else if ((!menuItemFull.getIsFeatured() || menuItemFull.getParentItemId() != null) && featuredMenuItems.contains(menuItemFull.getId())) {
featuredMenuItems.remove(menuItemFull.getId());
} else if(!menuItemFull.getIsFeatured() && menuItemFull.getParentItemId() == null && !menuItems.contains(menuItemFull.getId())) {
menuItems.add(menuItemFull.getId());
} else if ((menuItemFull.getIsFeatured() || menuItemFull.getParentItemId() != null) && menuItems.contains(menuItemFull.getId())) {
menuItems.remove(menuItemFull.getId());
}
menuDAO.save(menu);
return menuItemFull;
}
public Boolean deleteMenuItem(String id, String portalPid) throws Exception {
Menu menu = menuDAO.findByPortalPid(portalPid);
if(menu == null) {
// EXCEPTION - ContentNotFoundException
throw new ContentNotFoundException("deleteMenuItem: No Menu found for portal pid: "+portalPid);
}
List<String> featuredMenuItems = menu.getFeaturedMenuItems();
List<String> menuItems = menu.getMenuItems();
if(featuredMenuItems.contains(id)) {
featuredMenuItems.remove(id);
} else if(menuItems.contains(id)) {
menuItems.remove(id);
}
menuDAO.save(menu);
// menuItemDAO.delete(id);
log.debug("delete menu item; "+id);
List<String> menuItemsToDelete = new ArrayList<>();
menuItemsToDelete.add(id);
return deleteMenuItems(menuItemsToDelete, portalPid);
}
public Boolean deleteMenuItems(List<String> menuItems, String portalPid) throws Exception {
if(menuItems == null) {
return true;
}
for (String id: menuItems) {
MenuItem menuItem = menuItemDAO.findById(id);
if(!portalPid.equals(menuItem.getPortalPid())) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("Delete Menu Items: MenuItem with id: "+id+" has portalPid: "+menuItem.getPortalPid()+" instead of "+portalPid);
}
deleteMenuItems(menuItem.getItems(), portalPid);
if(menuItem.getParentItemId() != null && !menuItem.getParentItemId().equals("")) {
MenuItem parent = menuItemDAO.findById(menuItem.getParentItemId());
List<String> siblingsOfDeleted = parent.getItems();
siblingsOfDeleted.remove(id);
parent.setItems(siblingsOfDeleted);
menuItemDAO.save(parent);
}
menuItemDAO.delete(id);
}
return true;
}
public Boolean deleteMenuByPortalPid(String portalPid) throws Exception {
Menu menu = menuDAO.findByPortalPid(portalPid);
if(menu != null) {
deleteMenuItems(menu.getMenuItems(), portalPid);
deleteMenuItems(menu.getFeaturedMenuItems(), portalPid);
menuDAO.deleteByPortalPid(portalPid);
}
return true;
}
public Boolean reorderMenuItems(List<MenuItemFull> menuItemsFull, String portalPid) {
List<String> menuItemIds = new ArrayList<>();
// menuItemIds = menuItemsFull.stream().map((MenuItem menuItem) -> menuItem.getId()).collect(Collectors.toList());
boolean isFeatured = menuItemsFull.get(0).getIsFeatured();
String parentId = menuItemsFull.get(0).getParentItemId();
for (MenuItemFull menuItem: menuItemsFull) {
if (!portalPid.equals(menuItem.getPortalPid())) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("reorderMenuItems: MenuItems for reordering have not the same portalPid");
}
if(menuItem.getIsFeatured() != isFeatured) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("reorderMenuItems: MenuItems for reordering have not the same isFeatured");
}
if((menuItem.getParentItemId() == null && parentId != null) || (parentId == null && menuItem.getParentItemId() != null) || (parentId != null && !menuItem.getParentItemId().equals(parentId))) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("reorderMenuItems: MenuItems for reordering have not the same parentItemId");
}
menuItemIds.add(menuItem.getId());
}
List<String> savedMenuItems;
if(parentId != null) {
MenuItem parent = menuItemDAO.findById(parentId);
savedMenuItems = parent.getItems();
menuItemIds = this.addSavedMenuItems(savedMenuItems, menuItemIds, menuItemsFull);
parent.setItems(menuItemIds);
menuItemDAO.save(parent);
} else if(isFeatured) {
Menu menu = menuDAO.findByPortalPid(portalPid);
savedMenuItems = menu.getFeaturedMenuItems();
menuItemIds = this.addSavedMenuItems(savedMenuItems, menuItemIds, menuItemsFull);
menu.setFeaturedMenuItems(menuItemIds);
menuDAO.save(menu);
} else {
Menu menu = menuDAO.findByPortalPid(portalPid);
savedMenuItems = menu.getMenuItems();
menuItemIds = this.addSavedMenuItems(savedMenuItems, menuItemIds, menuItemsFull);
menu.setMenuItems(menuItemIds);
menuDAO.save(menu);
}
return true;
}
private List<String> addSavedMenuItems(List<String> savedMenuItems, List<String> menuItemIds, List<MenuItemFull> menuItemsFull) {
for (String menuId : savedMenuItems) {
if (!menuItemIds.contains(menuId)) {
menuItemIds.add(menuId);
}
}
return menuItemIds;
}
private MenuItem getMenuItemByMenuItemFull(MenuItemFull menuItemFull) {
MenuItem menuItem = new MenuItem();
menuItem.setId(menuItemFull.getId());
menuItem.setTitle(menuItemFull.getTitle());
menuItem.setUrl(menuItemFull.getUrl());
menuItem.setType(menuItemFull.getType());
menuItem.setTarget(menuItemFull.getTarget());
menuItem.setRoute(menuItemFull.getRoute());
menuItem.setPortalPid(menuItemFull.getPortalPid());
menuItem.setParentItemId(menuItemFull.getParentItemId());
menuItem.setIsFeatured(menuItemFull.getIsFeatured());
List<MenuItemFull> menuItemsFull = menuItemFull.getItems();
List<String> menuItems = new ArrayList<String>();
if(menuItemsFull != null) {
for (MenuItemFull childMenuItemFull : menuItemsFull) {
menuItems.add(childMenuItemFull.getId());
}
}
menuItem.setItems(menuItems);
return menuItem;
}
public Menu toggleMenu(String pid, String status, String isFeatured) throws Exception {
Menu menu = menuDAO.findByPortalPid(pid);
if(isFeatured != null && Boolean.parseBoolean(isFeatured)) {
menu.setFeaturedMenuEnabled(Boolean.parseBoolean(status));
} else {
menu.setMenuEnabled(Boolean.parseBoolean(status));
}
return menuDAO.save(menu);
}
}

View File

@ -2,13 +2,18 @@ package eu.dnetlib.uoaadmintools;
import eu.dnetlib.uoaadmintools.dao.*; import eu.dnetlib.uoaadmintools.dao.*;
import eu.dnetlib.uoaadmintoolslibrary.dao.*; import eu.dnetlib.uoaadmintoolslibrary.dao.*;
import eu.dnetlib.uoaadmintoolslibrary.emailSender.EmailSender;
import eu.dnetlib.uoaadmintoolslibrary.entities.Page; import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Profile;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.List;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
public class UoaAdminToolsApplicationTests { public class UoaAdminToolsApplicationTests {
@ -37,6 +42,8 @@ public class UoaAdminToolsApplicationTests {
@Autowired @Autowired
private PortalSubscribersDAO portalSubscribersDAO; private PortalSubscribersDAO portalSubscribersDAO;
@Autowired
private EmailSender emailSender;
/* /*
@Test @Test
@ -218,4 +225,11 @@ public class UoaAdminToolsApplicationTests {
// } // }
// } // }
@Test
public void test() {
String mail = "kgalouni@di.uoa.gr";
List<String> mails = new ArrayList<>();
mails.add(mail);
emailSender.send(mails, "Test Subject", "Test Body", false);
}
} }