Fórum

How to create a blog entry programmatically

Đorđe Torbica, modificado 10 Anos atrás.

How to create a blog entry programmatically

New Member Postagens: 7 Data de Entrada: 21/02/14 Postagens Recentes
Hi,

what is easiest way to create blog entry programmatically?

I wanted to use soap webservices but method AddEntry of BlogsEntryService is not more supported in version 6.1 and 6.2.

Thanks,
Dorde
thumbnail
James Falkner, modificado 10 Anos atrás.

RE: How to create a blog entry programmatically

Liferay Legend Postagens: 1399 Data de Entrada: 17/09/10 Postagens Recentes
Đorđe Torbica:
Hi,

what is easiest way to create blog entry programmatically?

I wanted to use soap webservices but method AddEntry of BlogsEntryService is not more supported in version 6.1 and 6.2.

Thanks,
Dorde


Hey Đorđe, welcome to the community! I posted a blog post a while ago about how to programmatically create things like Blog posts using Java code. This may help (though it does not do this remotely - the java code was part of a portlet running on the server). But it should be easily mapped to Liferay's built-in JSON web services for blogs (if you have Liferay running on your local machine, you can visit http://localhost:8080/api/jsonws to see all of the JSON web services available to you, along with forms to test them out).
Đorđe Torbica, modificado 10 Anos atrás.

RE: How to create a blog entry programmatically

New Member Postagens: 7 Data de Entrada: 21/02/14 Postagens Recentes
Thank you for your answer. I chose jsonws. I am very close to solution but I am getting famous error:

No Group exists with the primary key 10180


HttpPost post = new HttpPost(
					"/api/secure/jsonws/blogsentry/add-entry");
			
			List<namevaluepair> params = new ArrayList<namevaluepair>();

			params.add(new BasicNameValuePair("title", "Hello1"));
			params.add(new BasicNameValuePair("description", "description"));
			params.add(new BasicNameValuePair("content", "Jira issue is fixed"));
			params.add(new BasicNameValuePair("displayDateMonth", "1"));
			params.add(new BasicNameValuePair("displayDateDay", "1"));
			params.add(new BasicNameValuePair("displayDateYear", "2014"));
			params.add(new BasicNameValuePair("displayDateHour", "1"));
			params.add(new BasicNameValuePair("displayDateMinute", "1"));
			params.add(new BasicNameValuePair("allowPingbacks", "true"));
			params.add(new BasicNameValuePair("allowTrackbacks", "true"));
			params.add(new BasicNameValuePair("trackbacks", ""));
			params.add(new BasicNameValuePair("smallImage", "false"));
			params.add(new BasicNameValuePair("smallImageURL", "1"));
			params.add(new BasicNameValuePair("smallImageFileName", "1"));
			params.add(new BasicNameValuePair("-smallImageInputStream", ""));			
			params.add(new BasicNameValuePair("serviceContext.scopeGroupId", "10180"));
			params.add(new BasicNameValuePair("-p_auth", ""));
</namevaluepair></namevaluepair>


How can I get scopeGroupId over JSON ?
thumbnail
Hitesh Methani, modificado 10 Anos atrás.

RE: How to create a blog entry programmatically

Regular Member Postagens: 171 Data de Entrada: 24/06/10 Postagens Recentes
Hello Đorđe Torbica,

You can get scopeGroupId from themeDisplay in java.
You can pass it from java to jsp or your js function call.
themedDisplay.getScopeGroupId() will return current group id.

Thanks,
Hitesh M
Đorđe Torbica, modificado 10 Anos atrás.

RE: How to create a blog entry programmatically

New Member Postagens: 7 Data de Entrada: 21/02/14 Postagens Recentes
But my application does not have any references to jsp, portlets or javascript. (it is a swing application)
I would like to use only pure JSON API.
thumbnail
Hitesh Methani, modificado 10 Anos atrás.

RE: How to create a blog entry programmatically

Regular Member Postagens: 171 Data de Entrada: 24/06/10 Postagens Recentes
In that case you will have to fire another json request to get group id from group name,
groupService contains a method to get group from group name.
public static com.liferay.portal.model.Group getGroup(long companyId,java.lang.String name).
You will require a group name in order to get group id or else you can specify a static group id from database(group table) if it fits your requirement.

Thanks,
Hitesh Methani.
Đorđe Torbica, modificado 10 Anos atrás.

RE: How to create a blog entry programmatically

New Member Postagens: 7 Data de Entrada: 21/02/14 Postagens Recentes
Thank you for your good hints. I find out a groupId in database, but now I am getting:

HTTP/1.1 200 OK
{"exception":"java.lang.NullPointerException"}

Unfortunately there is nothing about this in logs. In access log I see POST call, but I have no clue what is problem now.
thumbnail
James Falkner, modificado 10 Anos atrás.

RE: How to create a blog entry programmatically

Liferay Legend Postagens: 1399 Data de Entrada: 17/09/10 Postagens Recentes
Đorđe Torbica:
Thank you for your good hints. I find out a groupId in database, but now I am getting:

HTTP/1.1 200 OK
{"exception":"java.lang.NullPointerException"}

Unfortunately there is nothing about this in logs. In access log I see POST call, but I have no clue what is problem now.


Here is a wild guess. Try:
params.add(new BasicNameValuePair("serviceContext", "{scopeGroupId: 10180}"));


instead of the line you have now.
Đorđe Torbica, modificado 9 Anos atrás.

RE: How to create a blog entry programmatically

New Member Postagens: 7 Data de Entrada: 21/02/14 Postagens Recentes
After a lot of small problems I managed to get this working.

Last issue to solve is this one:
After a blog entry is added, it has status "Scheduled".

What should I do to get it published ?

I tried with
params.add(new BasicNameValuePair("serviceContext.workflowAction", "WorkflowConstants.ACTION_PUBLISH")); ,
params.add(new BasicNameValuePair("serviceContext.workflowAction", "ACTION_PUBLISH")) and
params.add(new BasicNameValuePair("serviceContext.workflowAction", "0"));
but without success.
thumbnail
Hitesh Methani, modificado 9 Anos atrás.

RE: How to create a blog entry programmatically

Regular Member Postagens: 171 Data de Entrada: 24/06/10 Postagens Recentes
That's great.!!

Let's hope last one gets solved.

Not sure, but try setting the property in portal-ext
"#
# Set this to true if blogs should be published to live by default.
#
blogs.publish.to.live.by.default=true
"

Which is false by default.

Hope this solves the problem.

Regards,
Hitesh M