如何以编程方式创建Liferay 7结构?

编程入门 行业动态 更新时间:2024-10-26 14:28:27
本文介绍了如何以编程方式创建Liferay 7结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Liferay 7中,如何创建结构? 这是我的尝试:

In Liferay 7, how to create a structure from a Java module? Here is my attempt:

Map<Locale, String> nameMap = new HashMap<Locale, String>(); nameMap.put(Locale.JAPAN, "The name"); Map<Locale, String> descriptionMap = new HashMap<Locale, String>(); descriptionMap.put(Locale.JAPAN, "The description"); DDMForm ddmForm = DDMUtil.getDDMForm("<here goes my real JSON form>"); DDMFormLayout ddmFormLayout = DDMUtil.getDefaultDDMFormLayout(ddmForm); DDMStructureLocalServiceUtil.addStructure( 20156, // userId 33421, // groupId DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID, // parentStructureId PortalUtil.getPortal().getClassNameId(DDLRecordSet.class), // classNameId new Long(CounterLocalServiceUtil.increment()).toString(), // structureKey nameMap, descriptionMap, ddmForm, ddmFormLayout, StorageType.JSON.toString(), 0, // type new ServiceContext() );

在数据库的DDMStructure表中创建该结构:

The structure gets created in the database's DDMStructure table:

不幸的是,它没有出现在该网站的Liferay UI中:

Unfortunately, it does not appear in that site's Liferay UI:

如何使其显示?

  • 在创建过程中或加载UI时,Liferay日志中均未显示错误.
  • 当我手动创建结构时,它会正确显示.
  • 针对Liferay 6的问题的解决方案,我也尝试过,导致同样的问题.
  • 我注意到手动创建结构时,在ResourcePermission表中添加了3行...在Java中创建结构时,我也应该创建这3个对象吗?
  • No error appear in Liferay's log during creation nor when loading the UI.
  • When I create a structure manually, it shows up correctly.
  • The solution to this question for Liferay 6, which I tried too, leads to the same problem.
  • I noticed that when creating a structure manually, 3 rows get added to the ResourcePermission table... when creating a structure in Java should I also create these 3 objects?
推荐答案

它是 classNameId 问题.用JournalArticle替换DDLRecordSet可解决此问题,使结构正确显示在Liferay的Structures UI中.

It is a classNameId problem. Replacing DDLRecordSet with JournalArticle solves the problem, making the structure show up correctly in Liferay's Structures UI.

有效的代码:

ServiceContext serviceContext = new ServiceContext(); serviceContext.setScopeGroupId(group.getGroupId()); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); Map<Locale, String> nameMap = new HashMap<Locale, String>(); nameMap.put(Locale.JAPAN, "The name"); Map<Locale, String> descriptionMap = new HashMap<Locale, String>(); descriptionMap.put(Locale.JAPAN, "The description"); DDMForm ddmForm = null; try { ddmForm = DDMUtil.getDDMForm(json); } catch (PortalException e) { log.error("Exception when parsing structure JSON", e); } DDMFormLayout ddmFormLayout = DDMUtil.getDefaultDDMFormLayout(ddmForm); long scopeClassNameId = PortalUtil.getPortal().getClassNameId(JournalArticle.class); long parentStructureId = DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID; String storageType = StorageType.JSON.toString(); String structureKey = "my structure"; try { DDMStructure ddmStructure = DDMStructureLocalServiceUtil.addStructure( user.getUserId(), group.getGroupId(), parentStructureId, scopeClassNameId, structureKey, nameMap, descriptionMap, ddmForm, ddmFormLayout, storageType, DDMStructureConstants.TYPE_DEFAULT, serviceContext); } catch (StructureDuplicateStructureKeyException e) { log.info("Skipping creation of structure that already exists"); } catch (PortalException e) { log.error("Exception when creating structure: " + structureDefinitionFilePath, e); }

更多推荐

如何以编程方式创建Liferay 7结构?

本文发布于:2023-11-03 16:43:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555604.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:结构   方式   Liferay

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!