From ad80551db76453186000ffc45bf9f8a6fd2f4630 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Wed, 9 Feb 2022 12:22:28 +0000 Subject: [PATCH] [Trunk | Admin tools]: MenuItemController.java & MenuItemDAO.java & MongoDBMenuItemDAO.java & MenuItem.java & MenuItemFull.java & MenuItemService.java: Added dynamically configurable Menu Items for specific portal. --- .../controllers/MenuItemController.java | 213 ++++++++++++++++++ .../uoaadmintools/dao/MenuItemDAO.java | 21 ++ .../dao/MongoDBDAOs/MongoDBMenuItemDAO.java | 23 ++ .../uoaadmintools/entities/menu/MenuItem.java | 96 ++++++++ .../entities/menu/MenuItemFull.java | 104 +++++++++ .../services/MenuItemService.java | 197 ++++++++++++++++ 6 files changed, 654 insertions(+) create mode 100644 src/main/java/eu/dnetlib/uoaadmintools/controllers/MenuItemController.java create mode 100644 src/main/java/eu/dnetlib/uoaadmintools/dao/MenuItemDAO.java create mode 100644 src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBDAOs/MongoDBMenuItemDAO.java create mode 100644 src/main/java/eu/dnetlib/uoaadmintools/entities/menu/MenuItem.java create mode 100644 src/main/java/eu/dnetlib/uoaadmintools/entities/menu/MenuItemFull.java create mode 100644 src/main/java/eu/dnetlib/uoaadmintools/services/MenuItemService.java diff --git a/src/main/java/eu/dnetlib/uoaadmintools/controllers/MenuItemController.java b/src/main/java/eu/dnetlib/uoaadmintools/controllers/MenuItemController.java new file mode 100644 index 0000000..c618ccc --- /dev/null +++ b/src/main/java/eu/dnetlib/uoaadmintools/controllers/MenuItemController.java @@ -0,0 +1,213 @@ +package eu.dnetlib.uoaadmintools.controllers; + +import eu.dnetlib.uoaadmintools.dao.NotificationsDAO; +import eu.dnetlib.uoaadmintools.entities.Notifications; +import eu.dnetlib.uoaadmintools.entities.menu.MenuItem; +import eu.dnetlib.uoaadmintools.entities.menu.MenuItemFull; +import eu.dnetlib.uoaadmintools.services.MenuItemService; +import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO; +import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; +import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalPage; +import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; +import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException; +import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@CrossOrigin(origins = "*") +public class MenuItemController { + private final Logger log = Logger.getLogger(this.getClass()); + + @Autowired + private MenuItemService menuItemService; + @Autowired + private PortalDAO portalDAO; + @Autowired + private RolesUtils rolesUtils; + +// @PreAuthorize("hasAnyAuthority(" + +// "@AuthorizationService.PORTAL_ADMIN, " + +// "@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))") + @RequestMapping(value = "/community/{pid}/menu", method = RequestMethod.GET) + public List getMenuItems(@PathVariable(value = "pid") String pid ) 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 Notifications: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community"); + } + + List menuItems = menuItemService.getMenuItems(pid); + if(menuItems == null || menuItems.size() == 0){ + 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; + } + + @RequestMapping(value = "/community/{pid}/menu/root/full", method = RequestMethod.GET) + public List getRootMenuItemsFull(@PathVariable(value = "pid") String pid ) 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 menuItems = menuItemService.getRootMenuItemsFull(pid); +// if(menuItems == null || menuItems.size() == 0){ +// throw new ContentNotFoundException("Root menu for community with pid: "+pid+" not found"); +// } + return menuItems; + } + + @RequestMapping(value = "/community/{pid}/menu/root", method = RequestMethod.GET) + public List getRootMenuItems(@PathVariable(value = "pid") String pid ) 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 menuItems = menuItemService.getMenuItemsByParent(null, pid); + if(menuItems == null || menuItems.size() == 0){ + 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 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 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(" + + "@AuthorizationService.PORTAL_ADMIN, " + + "@AuthorizationService.curator('community')," + + "@AuthorizationService.manager('community', #pid))") + @RequestMapping(value = "/community/{pid}/menu/update", method = RequestMethod.POST) + public MenuItemFull updateMenuItem(@PathVariable String pid, @RequestBody MenuItemFull menuItemFull) { + 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("updateMenuItem: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community"); + } + if(menuItemFull.getType() == null || + (menuItemFull.getType().equals("internal") && menuItemFull.getRoute() == null) || + (menuItemFull.getType().equals("external") && menuItemFull.getUrl() == null)) { + // EXCEPTION - MismatchingContent + throw new MismatchingContentException("insertMenuItem: A required field is missing in menu item: type="+menuItemFull.getType() + + " - url="+menuItemFull.getUrl() + " - route="+menuItemFull.getRoute()); + } + if(menuItemFull.getPortalPid() == null) { + menuItemFull.setPortalPid(pid); + } else if(!menuItemFull.getPortalPid().equals(pid)) { + // EXCEPTION - MismatchingContent + throw new MismatchingContentException("updateMenuItem: MenuItem has portalPid: "+menuItemFull.getPortalPid()+" instead of "+pid); + } + if(menuItemFull.getId() == null) { + // EXCEPTION - MismatchingContent + throw new MismatchingContentException("updateMenuItem: This MenuItem has no id."); + } + + return menuItemService.updateMenuItem(menuItemFull); + } + + @PreAuthorize("hasAnyAuthority(" + + "@AuthorizationService.PORTAL_ADMIN, " + + "@AuthorizationService.curator('community')," + + "@AuthorizationService.manager('community', #pid))") + @RequestMapping(value = "/community/{pid}/menu/save", method = RequestMethod.POST) + public MenuItemFull insertMenuItem(@PathVariable String pid, @RequestBody MenuItem menuItem) { + Portal portal = portalDAO.findByPid(pid); + if(portal == null){ + throw new ContentNotFoundException("Portal with pid: "+pid+" not found"); + } + if(portal.getType() == null || !portal.getType().equals("community")) { + // EXCEPTION - MismatchingContent + throw new MismatchingContentException("insertMenuItem: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community"); + } + if(menuItem.getType() == null || + (menuItem.getType().equals("internal") && menuItem.getRoute() == null) || + (menuItem.getType().equals("external") && menuItem.getUrl() == null)) { + // EXCEPTION - MismatchingContent + throw new MismatchingContentException("insertMenuItem: A required field is missing in menu item: type="+menuItem.getType() + + " - url="+menuItem.getUrl() + " - route="+menuItem.getRoute()); + } + if(menuItem.getPortalPid() == null) { + menuItem.setPortalPid(pid); + } else if(!menuItem.getPortalPid().equals(pid)) { + // EXCEPTION - MismatchingContent + throw new MismatchingContentException("insertMenuItem: MenuItem has portalPid: "+menuItem.getPortalPid()+" instead of "+pid); + } + if(menuItem.getId() != null) { + // EXCEPTION - MismatchingContent + throw new MismatchingContentException("insertMenuItem: MenuItem has already an id: "+menuItem.getId()); + } + + return menuItemService.insertMenuItem(menuItem, pid); + } + + @PreAuthorize("hasAnyAuthority(" + + "@AuthorizationService.PORTAL_ADMIN, " + + "@AuthorizationService.curator('community')," + + "@AuthorizationService.manager('community', #pid))") + @RequestMapping(value = "/community/{pid}/menu/delete", method = RequestMethod.POST) + public Boolean deleteMenuItem(@PathVariable String pid, @RequestBody String menuItemId) 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("Get Notifications: Portal with id: "+portal.getId()+" has type: "+portal.getType()+" instead of community"); + } + + return menuItemService.deleteMenuItem(menuItemId, pid); + } +} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/dao/MenuItemDAO.java b/src/main/java/eu/dnetlib/uoaadmintools/dao/MenuItemDAO.java new file mode 100644 index 0000000..2ef7b86 --- /dev/null +++ b/src/main/java/eu/dnetlib/uoaadmintools/dao/MenuItemDAO.java @@ -0,0 +1,21 @@ +package eu.dnetlib.uoaadmintools.dao; + +import eu.dnetlib.uoaadmintools.entities.menu.MenuItem; + +import java.util.List; + +public interface MenuItemDAO { + List findAll(); + List findByParentItemId(String parentId); + + MenuItem findById(String Id); + + List findByPortalPid(String portalPid); + List findByParentItemIdAndPortalPid(String parentId, String portalPid); + + MenuItem save(MenuItem menuItem); + + void deleteAll(); + + void delete(String id); +} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBDAOs/MongoDBMenuItemDAO.java b/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBDAOs/MongoDBMenuItemDAO.java new file mode 100644 index 0000000..1c7b5a2 --- /dev/null +++ b/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBDAOs/MongoDBMenuItemDAO.java @@ -0,0 +1,23 @@ +package eu.dnetlib.uoaadmintools.dao.MongoDBDAOs; + +import eu.dnetlib.uoaadmintools.dao.MenuItemDAO; +import eu.dnetlib.uoaadmintools.entities.menu.MenuItem; +import org.springframework.data.mongodb.repository.MongoRepository; + +import java.util.List; + +public interface MongoDBMenuItemDAO extends MenuItemDAO, MongoRepository { + List findAll(); + List findByParentItemId(String parentId); + + MenuItem findById(String Id); + + List findByPortalPid(String portalPid); + List findByParentItemIdAndPortalPid(String parentId, String portalPid); + + MenuItem save(MenuItem menuItem); + + void deleteAll(); + + void delete(String id); +} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/entities/menu/MenuItem.java b/src/main/java/eu/dnetlib/uoaadmintools/entities/menu/MenuItem.java new file mode 100644 index 0000000..9eade1e --- /dev/null +++ b/src/main/java/eu/dnetlib/uoaadmintools/entities/menu/MenuItem.java @@ -0,0 +1,96 @@ +package eu.dnetlib.uoaadmintools.entities.menu; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.springframework.data.annotation.Id; + +import java.util.List; + +public class MenuItem { + @Id + @JsonProperty("_id") + private String id; // for root menu in order to close the dropdown when clicked + + String title; + String url; // external url + String route; // internal url - using angular routing and components + String type; // internal or external + List items; + String parentItemId; + String portalPid; + + public MenuItem(){ + + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getRoute() { + return route; + } + + public void setRoute(String route) { + this.route = route; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + public String getParentItemId() { + return parentItemId; + } + + public void setParentItemId(String parentItemId) { + this.parentItemId = parentItemId; + } + + public String getPortalPid() { + return portalPid; + } + + public void setPortalPid(String portalPid) { + this.portalPid = portalPid; + } + + @Override + public String toString() { + return "MenuItem{" + + "id='" + id + '\'' + +// ", notifyForNewManagers=" + notifyForNewManagers + + '}'; + } +} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/entities/menu/MenuItemFull.java b/src/main/java/eu/dnetlib/uoaadmintools/entities/menu/MenuItemFull.java new file mode 100644 index 0000000..809ad43 --- /dev/null +++ b/src/main/java/eu/dnetlib/uoaadmintools/entities/menu/MenuItemFull.java @@ -0,0 +1,104 @@ +package eu.dnetlib.uoaadmintools.entities.menu; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.springframework.data.annotation.Id; + +import java.util.List; + +public class MenuItemFull { + @Id + @JsonProperty("_id") + private String id; // for root menu in order to close the dropdown when clicked + + String title; + String url; // external url + String route; // internal url - using angular routing and components + String type; // internal or external + List items; + String parentItemId; + String portalPid; + + public MenuItemFull(){} + public MenuItemFull(MenuItem menuItem){ + setId(menuItem.getId()); + setTitle(menuItem.getTitle()); + setUrl(menuItem.getUrl()); + setType(menuItem.getType()); + setRoute(menuItem.getRoute()); + setParentItemId(menuItem.getParentItemId()); + setPortalPid(menuItem.getPortalPid()); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getRoute() { + return route; + } + + public void setRoute(String route) { + this.route = route; + } + + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + public String getParentItemId() { + return parentItemId; + } + + public void setParentItemId(String parentItemId) { + this.parentItemId = parentItemId; + } + + public String getPortalPid() { + return portalPid; + } + + public void setPortalPid(String portalPid) { + this.portalPid = portalPid; + } + + @Override + public String toString() { + return "MenuItemFull{" + + "id='" + id + '\'' + +// ", notifyForNewManagers=" + notifyForNewManagers + + '}'; + } +} diff --git a/src/main/java/eu/dnetlib/uoaadmintools/services/MenuItemService.java b/src/main/java/eu/dnetlib/uoaadmintools/services/MenuItemService.java new file mode 100644 index 0000000..04a8604 --- /dev/null +++ b/src/main/java/eu/dnetlib/uoaadmintools/services/MenuItemService.java @@ -0,0 +1,197 @@ +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 menuItemsFull = new ArrayList<>(); + for(String menuItemString : menuItem.getItems()) { + menuItemsFull.add(this.getMenuItemFull(menuItemString, maxDepth-1)); + } + menuItemFull.setItems(menuItemsFull); + + return menuItemFull; + } + + public List getMenuItems(String portalPid) { + if(portalPid != null) { + return menuItemDAO.findByPortalPid(portalPid); + } else { + return menuItemDAO.findAll(); + } + } + + public List getMenuItemsByParent(String parentId, String portalPid) { + if(portalPid != null) { + return menuItemDAO.findByParentItemIdAndPortalPid(parentId, portalPid); + } else { + return menuItemDAO.findByParentItemId(parentId); + } + } + + public List getRootMenuItemsFull(String portalPid) { + List rootMenuItems = this.getMenuItemsByParent(null, portalPid); + List rootMenuItemsFull = new ArrayList<>(); + for(MenuItem rootMenuItem : rootMenuItems) { + MenuItemFull rootMenuItemFull = new MenuItemFull(rootMenuItem); + + List 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 menuItems = new ArrayList(); + menuItem.setItems(menuItems); + } + menuItemDAO.save(menuItem); + + if(parent != null) { + List 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 menuItems = new ArrayList<>(); + menuItems.add(id); + return deleteMenuItems(menuItems, portalPid); + } + + public Boolean deleteMenuItems(List 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 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 menuItemsFull = menuItemFull.getItems(); + List menuItems = new ArrayList(); + if(menuItemsFull != null) { + for (MenuItemFull childMenuItemFull : menuItemsFull) { + menuItems.add(childMenuItemFull.getId()); + } + } + menuItem.setItems(menuItems); + + return menuItem; + } +}