Monday, 22 April 2013

Publish a Project and all contents in the Project


***
We can publish a Project and all contents in project if and only if they(content) are in 'Pending' status.
***

1. Create a Workflow for content items, With two stages.
-> Create workflow action (Publish)
-> Create two workflow stages
-> In first WorkflowStage,
Run on Entering Stage : None
Run on Exiting Stage : None
   Joint approval: check
Enter comment on approval: check
Approver: required user
-> In second WorkflowStage,
Run on Entering Stage: Assign the publish action you created
Run on Exiting Stage: None
   Joint approval: check
Enter comment on approval: check
Approver: required user
-> Create Workflow
-> Workflow Stages:
first workflowstage
second workflowstage
-> Reject Stage: None

2. Create a content item based on above created workflow and save. Content will be in "Draft" status.

3. Create a New Project,
        -> Publish Option : Manual
-> Approval  : Add user who will approve the project
-> Require approval from : depends on your requirement
-> Require a comment from the approver : Check
-> Save and close, now created project will be in "Active" state.

4. Now add contents(draft status) to project.
5. In project, To move content into next status, check the content and click on 'More' dropdown and select 'Approve'.
6. Content move to the next state 'Publish Pending'.
7. Now we have to submit project for 'Review' by clicking 'Submit for Review' button.
8. Project change to 'Review' state.
9. Now we have to approve project by clicking 'Approve Project' button.
10. Here project change to 'Pending' state.
11. Now we can publish project by clicking 'Publish Project' button.
12. Here project state change to 'Published' and content state also changes to 'Published'.

Through JSP we can publish the project by running below code


<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="com.ibm.workplace.wcm.api.exceptions.*"%>
<%@ page import="java.util.*,javax.servlet.jsp.JspWriter,java.io.*,java.util.Iterator"%>

<%

try{
// Workspace
Workspace myworkspace = WCM_API.getRepository().getSystemWorkspace();
myworkspace.login();
myworkspace.setCurrentDocumentLibrary(myworkspace.getDocumentLibrary("LibraryName"));

DocumentId docid = null;
DocumentIdIterator docid_iterator = null;
String projectName = null;
Project userProject = null;

// Specifing our project
docid_iterator = myworkspace.findByName(DocumentTypes.Project, "ProjectName");

if(docid_iterator.hasNext()){
docid = docid_iterator.nextId();
userProject = (Project)myworkspace.getById(docid);
// To get project name
projectName = userProject.getName();
// To get item count in project
long val = userProject.getItemCount();
//out.println("Poject Name is :: "+projectName+"<br>Number of Items in Project :: "+val);
// to get items/content of specified project
Iterator ie = userProject.getItems();
while(ie.hasNext()) {
Content con_obj = (Content)ie.next();
//out.println("<br>Content Object :: "+con_obj);
// To get approver names for content item
String approvers[] = con_obj.getCurrentApprovers();
for(int i=0; i<approvers.length; i++){
//out.println("<br>Content Approvers are :: "+approvers[i]);
}
// Move content to nextworkflowstage
con_obj.nextWorkflowStage();
}
}

// To get approver names for Project
String projectapprover[] = userProject.getCurrentApprovers();
for(int i=0; i<projectapprover.length; i++){
//out.println("<br>Project Approvers are :: "+projectapprover[i]);
}

// To publish a project when all items in project are move to next state
userProject.publish();

}
catch(Exception e){
e.printStackTrace();
}

%>






No comments:

Post a Comment