Skip to Content

INTRODUCTION:

    With the help of Approval process, few authorized persons can control the publishing of content in Knowledge Management (KM) repository. This helps to make sure that content is checked by approvers before it is published.

    Before approvers can use this feature, few steps are required and few lines of code.

 

PREREQUISITES:

    For detailed prerequisites, please refer the following link from SAP library:-

http://help.sap.com/saphelp_nw04/helpdata/en/04/9053ad76fd0948b4ec2abf97898a3e/content.htm

 

PUBLISHING WITH AN APPROVAL PROCESS:-

    Please refer to following link:-

http://help.sap.com/saphelp_nw04/helpdata/en/db/a4bf4db1d011d5993800508b6b8b11/frameset.htm

 

REQUIREMENT:- 

  1. Assuming that approvers list has been configured as mentioned in the link under prerequisites section, and approval and versioning process are enabled for the required folder; user with write permission edits content and saves the XML form in KM.
  2. Now approvers can review this content and publish it or reject it. If published, the content will be visible to end users having only read permission.
  3. When user with write permission clicks on “Edit” button to edit any XML form (I call it as “Author Mode ON”), then the latest XML data, irrespective of its release state, should be displayed. But when he is not editing it (i.e. “Author Mode Off”) but just viewing it, then latest ‘released’ content should be displayed.
  4. For end user, only published/released XML form data will be displayed.

 

These above mentioned requirements were implemented using KM APIs in webdynpro PAR component in enterprise perspective of NWDS.

 

Following is the code that implements above mentioned requirements :-

(Some part of the code was referred from SDN forums.)

 

/*******************Logic for approval/versioning starts. *******************/

//Obtain IResource object for the required RID. (Resource Identification)                          

IResource resource = ResourceFactory.getInstance().getResource(rid,resourceContext);

//Obtain ISecurityManager object to retrieve user permission

ISecurityManager ISecurityMangr = resource.getRepositoryManager().getSecurityManager(resource);

//flag is set if a released Doc is found

boolean ReleasedDocFound = false;

// check if multiple versions are present. If not then only one version is present and hence no use of moving ahead.                     

if( resource.isVersioned() ){

         //check user’s write permission    

        if(!(ISecurityMangr.isAllowed(resource,user,Permission.WRITE_CONTENT)) ) {          

                        // user doesnt have write permission.

                        //dont do anything

        }

       else{

                        //user has write permission

                        // So now check if Author mode is ON. If its ON, don’t do anything since by default KM will retrieve latest version irrespective of its release state.

                       

                        if(showAdvanceoptions){

                                    //author mode is ON

                                    //dont do anything

                        }

                               else{

                                    //author mode is OFF. Check for latest released doc.

                                  //So for that first get the current state of current version and                               if it is released then our work is done, else we have to                                 loop through all the previous versions, one by one, until we find a released doc.  

 

                                    //logic for getting latest released doc.

                                    //Code for getting the STATE of the resource

                                    IResourceFactory resfactory = ResourceFactory.getInstance();

                                               IRepositoryServiceFactory repServiceFactory = resfactory.getServiceFactory();

                                    //state for current resource

                                    IStatemanagementManager stateMgr = (IStatemanagementManager) repServiceFactory.getRepositoryService(resource, “StatemanagementRepositoryService”);

                                               IStatemanagementResource statRsrc = stateMgr.getStatemangementResource(resource);

                                               IStatemanagementUtilsResource statRsrcUtils = statRsrc.getUtils();

                                               IState state = statRsrcUtils.readState();

                                                           

                                              if(state.toString().trim().equalsIgnoreCase(“Released”)){

                                                //dont do anything if current resource is released.

                                            ReleasedDocFound = true;

                                              }

                                              else{

                                    //current resource is not released.

                                    IVersionHistory versions = resource.getVersionHistory();

                                                int currentVersionNumber = versions.size()-1;

                                                for(int i=currentVersionNumber; i > 0; i–){

                                                      IResource currentVersion = versions.get(i);

                                                     stateMgr = (IStatemanagementManager)  repServiceFactory.getRepositoryService(currentVersion, “StatemanagementRepositoryService”);

                                                      statRsrc = stateMgr.getStatemangementResource(currentVersion);

                                                      statRsrcUtils = statRsrc.getUtils();

                                         state = statRsrcUtils.readState();                         

                                                      if(state.toString().trim().equalsIgnoreCase(“Released”)){

                                                            //found released resource

                                                            rid = currentVersion.getRID();

                                                            ReleasedDocFound = true;

                                                                                break;

                                                }

                                                                       

                                                                       

                                    }          

                                                           

                                                           

                                                if(!ReleasedDocFound){

                                                //No Released Documents were found.

                                                DontShowPage = true;

                                                                response.write(“Content is not yet approved!”);

                                                                                   

                                               }          

                                                  

                                                  

                        }                      

                                                           

            }

                                               

}

}                                  

                                   

            /*******************end of version/approvel logic *************/

 

 

References:-

            http://www.sdn.sap.com/

            http://www.help.sap.com/

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply