3

I have created structure and template through portal UI. Now I am creating the journal article programmatically in the action class. While creating a journal article in the action class I want to set the existing structure and template to this journal article. I am trying to use the following method but here what is meant by ddmStructureKey and ddmTemplateKey.

Are those related to my requirement only?

JournalArticleLocalServiceUtil.addArticle(userId, groupId, folderId, titleMap, descriptionMap, content, ddmStructureKey, ddmTemplateKey, serviceContext)

Help me out on this unknown thing. Thanks.

Tim Ogilvy
  • 1,923
  • 1
  • 24
  • 36
  • Please post more context about what you are trying to achieve and what you have done so far. – Tim Ogilvy Mar 29 '16 at 05:25
  • Context is very simple.I need to set the structure and template to the journal article programmatically.In the above i posted which method used to get it and in this method unaware of two parameters. – Kona Laxman Deepak Mar 29 '16 at 06:05
  • Please use your space bar and shift key when typing messages. There should be a space after the '.' character and the word 'I', as in 'myself' has a capital letter. I'm not a liferay expert, so I will let someone else help you answer your question, however if you are hoping people will assist you, please provide as much detail as possible. Thanks! – Tim Ogilvy Mar 29 '16 at 06:13
  • the ddmStructure and ddmTemplateKey are the structure of the article and the template(velocity,vm) to render that article. – Romeo Sheshi Mar 29 '16 at 08:38
  • Looking at the implementation of `JournalArticleLocalServiceUtil.addArticle` reveals that `ddmStructureKey` and `ddmTemplateKey` set `structureId` and `templateId` respectively. So, you have pass the structure and template ids as string which you want to apply on your content. – Parkash Kumar Mar 29 '16 at 09:21
  • Ok Thank You.How to set the values to structure field as we are passing the content in the xml format.As i copied source of structure from UI and passing it to the content parameter of addArticle method – Kona Laxman Deepak Mar 29 '16 at 09:27
  • Similarly, you can set your `structureId` and `templateId` parameters to `add` method's `ddmStructureKey` and `ddmTemplateKey` arguments. – Parkash Kumar Mar 29 '16 at 10:06

2 Answers2

2

The following code i written to answer the above question and it worked out for me.Thanks to @Romeo Sheshi. I have hard coded some of the things.As per your requirement you can do whatever yo want.

ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
                Long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
                DDMStructure ddmStructure=DDMStructureLocalServiceUtil.getDDMStructure(11515);
                DDMTemplate ddmTemplate=DDMTemplateLocalServiceUtil.getDDMTemplate(11517);
                Map<Locale,String> titleMap=new HashMap<Locale,String>();
                titleMap.put(themeDisplay.getLocale(), "First Record");
                String content=
                        "<root available-locales='en_US' default-locale='en_US'>"
                                +"<dynamic-element dataType='string' indexType='keyword' name='Title' readOnly='false' repeatable='false' required='false' showLabel='true' type='text' width='small'>"
                                    +"<dynamic-content>FirstRecord</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='string' indexType='keyword' name='Description' readOnly='false' repeatable='false' required='false' showLabel='true' type='textarea' width='small'>"
                                +"  <dynamic-content>This the first one doing by programatically</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='image' fieldNamespace='wcm' indexType='keyword' name='DamImage' readOnly='false' repeatable='false' required='false' showLabel='true' type='wcm-image' width=''>"
                                +"  <dynamic-content>http://localhost:8080/documents/10184/0/welcome_community/0dc0adb1-b565-409a-b766-96d1e42b04fb?t=1459163274526</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='string' indexType='keyword' name='UserIdExcel' readOnly='false' repeatable='false' required='false' showLabel='true' type='text' width='small'>"
                                +"  <dynamic-content>458155</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='string' indexType='keyword' name='Username' readOnly='false' repeatable='false' required='false' showLabel='true' type='text' width='small'>"
                                +"  <dynamic-content>LaxmanDeepak</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='date' fieldNamespace='ddm' indexType='keyword' name='DateFromExcel' readOnly='false' repeatable='false' required='false' showLabel='true' type='ddm-date' width='small'>"
                                +"<dynamic-content>03/29/2016</dynamic-content>"
                                +"</dynamic-element>"
                            +"</root>";
                ServiceContext serviceContext = new ServiceContext();
                serviceContext.setScopeGroupId(themeDisplay.getScopeGroupId());
                serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

                JournalArticleLocalServiceUtil.addArticle(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), parentFolderId, titleMap, null, content, ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(), serviceContext);
0

the ddmStructure and ddmTemplateKey are the structure of the article and the template(velocity,freemarker) to render that article. if you use an empty string you pick up the default template and the default structure otherwise if you wont to use an your structure and template you have to fetch them with these services

DDMStructureLocalServiceUtil
DDMTemplateLocalServiceUtil
Romeo Sheshi
  • 901
  • 5
  • 7
  • Yeah i understood that point but which values i need to pass.Either id or name of the structure and template or anything other values. Because the method is expecting the values of String type – Kona Laxman Deepak Mar 29 '16 at 08:49
  • in the DDMTemplate there is a method getTemplateKey() so in the structure getStructureKey() – Romeo Sheshi Mar 29 '16 at 08:58
  • Thanks for your quick response it helped me out.And one more question i have here. Suppose my structure contains 2 text fields, Now how to set values to those fields in the xml file which is passing as value for content. – Kona Laxman Deepak Mar 29 '16 at 09:23
  • The article is an xml so you have to use some xml parser to add the value to it, or use an string concatenation based on your structure xml – Romeo Sheshi Mar 29 '16 at 09:41