Tuesday, April 7, 2009

update a content item's workflow stage and add approver comments in WCM 6

Question
You would like to use the IBM® Web Content Management (WCM) API to update a content item's workflow stage and add approver comments to the content item's history section. Which WCM API methods can be used?
 

Answer
The WCM API provides security features which allow workflow and approver functions such as approving content items and adding approver comments.


Example of methods to approve and restart content workflow
  1. First get the user workspace
  2. Next set the web content library.
  3. Build the document iterator.
  4. Get the document id.
  5. Check the document id lock status.
  6. Get the current content item.
  7. Check the status of the content item and determine what approver action you wish to execute.
  8. Update the content item history section with the approver comments.
  9. Save the content item.
  10. Execute the workflow action to move the content to the next workflow stage or restart the workflow.

** Note:** This example assumes that the last workflow stage is an expired stage and that content items in the expired stage are of the expired status.





Example code to move WCM content item within the workflow, add approver comments
//finds the document id of the content items that match by name

DocumentIdIterator docIdIterator = ws.findByName(DocumentTypes.Content, "testcontent");
DocumentId docId;
Content currentContent;
String contentName;
boolean save = false;
boolean restartWorkflow = false;
boolean moveToNextStage = false;
boolean locked = false;


//loops through the document id's found in the iterator
while(docIdIterator.hasNext())
{
docId = (DocumentId)docIdIterator.next();
locked = ws.isLocked(docId);

//get the current content item
currentContent = (Content)ws.getById(docId);

contentName = (String)currentContent.getName();
//standard out log message
System.out.println("Log: Testing WCM API: Retrieved content name = " + contentName );

if (!locked)
{
//Check content status, update workflow stage, and add comments to the content history log
if (currentContent.isExpired())
{
//standard out log message
System.out.println("Log: Testing WCM API: Content: "
+ contentName + " current status is expired.");

//standard out log message
System.out.println("Log: Testing WCM API: Adding approver comments to expired content.");

//Add approver comments to the content's history section
currentContent.addHistoryLogEntry("WCM API: Approver Comments: Restart workflow"
+ " and add comments to the content history section. ");

//Restart Workflow
restartWorkflow = true;
moveToNextStage = false;

//setting boolean flag to indicate the content item should be saved for the changes to take affect
save=true;
}
else if (currentContent.isPublished())
{
//standard out log message
System.out.println("Log: Testing WCM API: Content: "
+ contentName + " current status is published.");

//standard out log message
System.out.println("Log: Testing WCM API: Adding approver comments to published content.");

//Add approver comments to the content's history section
currentContent.addHistoryLogEntry("WCM API: Approver Comments: Expire published "
+ "content, move to the next workflow stage "
+ "and add comments to the content history section.");

//Move content to next workflow stage
moveToNextStage = true;
restartWorkflow = false;

//setting boolean flag to indicate the content item should be saved for the changes to take affect
save=true;
}
else if (currentContent.isDraft())
{
//standard out log message
System.out.println("Log: Testing WCM API: Content: "
+ contentName + " current status is draft.");

//standard out log message
System.out.println("Log: Testing WCM API: Adding approver comments to draft content.");

//Add approver comments to the content's history section
currentContent.addHistoryLogEntry("WCM API: Approver Comments: Move draft content "
+ "to next workflow stage and add comments to the content "
+ "history section.");

//Move content to next workflow stage
moveToNextStage = true;
restartWorkflow = false;

//setting boolean flag to indicate the content item should be saved for the changes to take affect
save=true;
}
else
{
//standard out log message
System.out.println("Log: Testing WCM API: Did not meet conditions to approve item.");
save=false;
moveToNextStage = false;
restartWorkflow = false;
}

}
else
{
//standard out log message
System.out.println("Log: Testing WCM API: Content name = "
+ (String)currentContent.getName()
+ " is locked. You can't update a locked item, please unlock it and try again. ");
}

//save the content item to persist the changes
if(save)
{
//standard out log message
System.out.println("Log: Testing WCM API: Saving Content name = "
+ (String)currentContent.getName());
ws.save(currentContent);
}

if (moveToNextStage)
{
//standard out log message
System.out.println("Log: Testing WCM API: Moving to next workflow stage.");
currentContent.nextWorkflowStage();
}

if (restartWorkflow)
{
//standard out log message
System.out.println("Log: Testing WCM API: Restarting workflow.");
currentContent.restartWorkflow();
}

}//end while



WCM api-javadoc: The Javadoc HTML files are located in the following location on your Web Content Management server:

under <WAS Profile Root>:
\AppServer\profiles\wp_profile\installedApps\nodename\wcm.ear\ilwwcm.war\webinterface\
Blogged with the Flock Browser