I need to create the Structure and Template progrmatically through java code.I used following code snippets.
Structure:
public void
There are couple of issues with your code:
You are not setting all the required properties, like groupId, companyId, classNameId, structureKey, dates
etc.
There isn't any setName
and setDescription
method for DDMStructure
or DDMTemplate
accepting String
argument (Liferay 6.2 GA2
). Instead, there are only setNameMap
and setDescriptionMap
methods for both accepting Map<Locale, String>
.
Use dynamic ids (structureId
and templateId
) in place of hard-coded ids, as following:
DDMStructure ddmStructure = DDMStructureUtil.create(CounterLocalServiceUtil.increment());
and
DDMTemplate ddmTemplate = DDMTemplateUtil.create(CounterLocalServiceUtil.increment());
For classNameId
, you can get it using it's value, like:
ClassName className = ClassNameLocalServiceUtil.getClassName("com.liferay.portlet.journal.model.JournalArticle");
long classNameId = className.getClassNameId();
Also, better to use update
over populated object in place of adding:
DDMStructureUtil.update(ddmStructure);
and
DDMTemplateUtil.update(ddmTemplate);
Additionally, if you have access to the ThemeDisplay
object, you can get groupId, companyId, userId, userFullName
from it. Also, set new Date()
for createDate
and modifiedDate
properties.