Category Archives: API Publishing jobs and reports

Publish a page – manually configure a publishing job

To configure a publishing job in detail jRQL has the class PublishingJob. To create a publishing job instance you need the start page and the flags if you want to publish with following pages and with related pages.

The following lines will prepare a publishin job starting from page with ID 34009 without following pages, but with related pages.

String logonGuid="0904ABF0E43443D2881FE7481339650E";
String sessionKey="490EC675042F4C5A8A6DF1ED63ADD7A6";
String projectGuid="268F46EF5EB74A75824856D3DA1C6597";

CmsClient client = new CmsClient(logonGuid);
Project project = client.getProject(sessionKey, projectGuid);

Page currentPg = project.getPageById(“34009”);
boolean withFollowingPages = false;
boolean withRelated = true;
PublishingJob job = new PublishingJob(currentPg, withFollowingPages, withRelated);

The job cannot be started at that moment, because neiter a project variant nor a language variant is set. Now you can use several methods to select the variants you need.

I prefer to use the project variant GUIDs and language variant GUID to define publishing, because they can not change.  To configure your publishing job with several project variants but only one language variant you should use this style:

job.addToPublish("projectVariantGuid1,projectVariantGuid2,projectVariantGuid3", ",", "languageVariantGuid");

The project variant GUIDs are contained in a simple string separated by , (the 2nd parameter) in our example and for one language variant guid. The style for the project variant GUIDs is a simple style for parameter handling.

If you need to add all combinations between project and language variants you should use this method:

currentPg.publishAllCombinations(withFollowingPages, projectVariantGuids, separator, languageVariantGuids)

This will add all combinations of project and language variants. You can override the withFollwingPages flag from the constructor. Either the projectVariantGuids and languageVariantGuids are separated by the same (the separator parameter).

Regardless how you configure your project and language variants you can decide which use should get the publishing e-mail. With the next line the e-mail will be send to the currently connected user, but it could be another existing user too.

job.setMailReceiver(client.getConnectedUser());

Finally you have to start your job using

job.start();

If you try to start a job which did not have at least one project and language variant you will get a IncompletePublishingJobException.

You can ask how many e-mail the job will send if you requested it:

job.getNumberOfPublishingMails();

Advertisements

Publish a page – basic style

You can immediately publish a page you have under your fingertips with directly available method on a page.

The easiest way to publish a page in one language and one project variant without following pages goes  like this:

String logonGuid="0904ABF0E43443D2881FE7481339650E";
String sessionKey="490EC675042F4C5A8A6DF1ED63ADD7A6";
String projectGuid="268F46EF5EB74A75824856D3DA1C6597";

CmsClient client = new CmsClient(logonGuid);
Project project = client.getProject(sessionKey, projectGuid);

ProjectVariant projectVariant = project.getProjectVariantByName(“project variant name”);
LanguageVariant languageVariant = project.getLanguageVariantByRfcLanguageId(“en”);
boolean withFollowingPages = false;

Page currentPg = project.getPageById(“34009”);
currentPg.publish(withFollowingPages, projectVariant, languageVariant);

This publish() method will not send an e-mail to the author per default. It return a PublishingJob instance.

There are several publish methods available on page to handle publishing of related pages and sending an e-mail or not. And of course publish for more project variants. Please check the javadoc for other publish methods (in most cases sufficient) or see the article how to configure a PublishingJob manually.

Getting project and language variants

Before we can start how to publish a page via jRQL I need to introduce how to get project variants and language variants.

You can get a project variant in two different ways, it is straight forward:

ProjectVariant pv1 = project.getProjectVariantByGuid(“project variant guid”);
ProjectVariant pv2 = project.getProjectVariantByName(“project variant name”);

Accessing the language variant you want you have more possiblities:

LanguageVariant lv1 = project.getLanguageVariantByGuid(“language variant guid”);
LanguageVariant lv2 = project.getLanguageVariantByName(“language variant name”);
LanguageVariant lv3 = project.getLanguageVariantByLanguage(“3 letter language code”);
LanguageVariant lv4 = project.getLanguageVariantByRfcLanguageId(“2 letter language code”);

You can get a language variant by GUID and by name, but jRQL offers 2 other ways. See the following screenshot what I mean with 2 and 3 letter code:

language_variant_codes

I often use the last method add address the language variants I need with the self entered RFC language code (the part before the hyphen). So I’m sure what language I will get and are not depending on the internal 3 letter code RedDot CMS uses.

Read further in the next article how to publish a page.