use of com.liferay.site.navigation.model.SiteNavigationMenuItem in project liferay-db-setup-core by ableneo.
the class SetupMenus method createMenuItem.
private static SiteNavigationMenuItem createMenuItem(long groupId, long userId, ServiceContext serviceContext, long parentMenuId, long parentMenuItem, MenuItem newMenuItem) {
// SiteNavigationMenuItemTypeConstants: layout(==page..), node, url
String type = newMenuItem.getType();
if (false == newMenuItem.getMenuItem().isEmpty()) {
type = "node";
} else if (type == null || "".equals(type)) {
type = "url";
} else {
type = "url";
}
LOG.info(" i setting item '" + newMenuItem.getName() + "' as '" + type + "': [" + newMenuItem.getTypeSettings() + "]");
// 'layout','groupId=20121 ; layoutUuid=accf0b5c-800f-d049-01bc-0a706e3fad15 ; privateLayout=false ; title=Search ; '
// defaultLanguageId=en_US ; name_en_US=tarsoldalak ;
String typeSettings = newMenuItem.getTypeSettings();
// LayoutSiteNavigationMenuItemType => page
// NodeSiteNavigationMenuItemType => submenu
// URLSiteNavigationMenuItemType => url link
SiteNavigationMenuItem savedItem = null;
try {
List<SiteNavigationMenuItem> items = SiteNavigationMenuItemLocalServiceUtil.getSiteNavigationMenuItems(parentMenuId, parentMenuItem);
for (SiteNavigationMenuItem item : items) {
if (item.getName().equals(newMenuItem.getName())) {
LOG.info("existing menu-item[" + newMenuItem.getName() + "]");
savedItem = item;
break;
}
}
} catch (Exception e) {
LOG.error("Can not list/find existing menu item '" + newMenuItem.getName() + "', CREATE NEW : ", e);
}
if (savedItem == null) {
try {
serviceContext.setUuid(UUID.randomUUID().toString());
LOG.info("Inserting menu-item[" + newMenuItem.getName() + "]");
savedItem = SiteNavigationMenuItemLocalServiceUtil.addSiteNavigationMenuItem(userId, groupId, parentMenuId, parentMenuItem, type, /*order,*/
typeSettings, serviceContext);
} catch (PortalException e) {
LOG.error("Can not add menu item '" + newMenuItem.getName() + "' : ", e);
return null;
}
}
try {
LOG.info("Updating menu-item[" + newMenuItem.getName() + "] @" + savedItem.getPrimaryKey() + "");
savedItem.setName(newMenuItem.getName());
savedItem.setType(type);
savedItem.setTypeSettings(typeSettings);
savedItem = SiteNavigationMenuItemLocalServiceUtil.updateSiteNavigationMenuItem(savedItem);
} catch (Exception e) {
LOG.error("Can not update menu item '" + newMenuItem.getName() + "' : ", e);
return null;
}
for (CustomFieldSetting cfs : newMenuItem.getCustomFieldSetting()) {
savedItem.getExpandoBridge().setAttribute(cfs.getKey(), cfs.getValue(), false);
}
return savedItem;
}
use of com.liferay.site.navigation.model.SiteNavigationMenuItem in project liferay-db-setup-core by ableneo.
the class SetupMenus method createMenuItems.
private static void createMenuItems(long groupId, Menu newMenu, long userId, ServiceContext serviceContext, SiteNavigationMenu menu) {
LOG.info("Adding menu-items for '" + menu.getName() + "'");
long parentMenuId = menu.getPrimaryKey();
long parentMenuItem = 0L;
// List<SiteNavigationMenuItem> currentItems = SiteNavigationMenuItemLocalServiceUtil.getSiteNavigationMenuItems(parentMenuId);
for (MenuItem newMenuItem : newMenu.getMenuItem()) {
// getExistingFromList(newMenuItem, currentItems);
SiteNavigationMenuItem menuItem = null;
// if (menuItem == null) {
menuItem = createMenuItem(groupId, userId, serviceContext, parentMenuId, parentMenuItem, newMenuItem);
// }
if (menuItem != null && false == newMenuItem.getMenuItem().isEmpty()) {
createMenuItems(groupId, userId, serviceContext, menu, menuItem, newMenuItem);
}
}
}
use of com.liferay.site.navigation.model.SiteNavigationMenuItem in project liferay-db-setup-core by ableneo.
the class SetupMenus method createMenuItems.
private static void createMenuItems(long groupId, long userId, ServiceContext serviceContext, SiteNavigationMenu parentMenu, SiteNavigationMenuItem parentMenuItem, MenuItem addFromMenuItems) {
String parentName = parentMenuItem.getName();
LOG.info(" i creating sub-menu-items under '" + parentName + "'");
long parentMenuId = parentMenu.getPrimaryKey();
long parentMenuItemId = parentMenuItem.getPrimaryKey();
// List<SiteNavigationMenuItem> currentItems = SiteNavigationMenuItemLocalServiceUtil.getSiteNavigationMenuItems(parentMenuId, parentMenuItemId);
for (MenuItem newMenuItem : addFromMenuItems.getMenuItem()) {
// SiteNavigationMenuItem menuItem = getExistingFromList(newMenuItem, currentItems);
SiteNavigationMenuItem menuItem = null;
// if (menuItem == null) {
menuItem = createMenuItem(groupId, userId, serviceContext, parentMenuId, parentMenuItemId, newMenuItem);
// }
if (menuItem != null && false == newMenuItem.getMenuItem().isEmpty()) {
createMenuItems(groupId, userId, serviceContext, parentMenu, menuItem, newMenuItem);
}
}
}
Aggregations