Saturday, June 16, 2012

System Object in the Portal for Connecting to SAP backend System

 
Portal System Landscape:

Portal system landscape is nothing but a collection of SAP or NON-SAP systems (SAP R3/CRM/BW etc), to retrieve the data from each system portal needs to create system object.
System Object: System Object is a set of connection properties to represent an external or SAP systems (SAP R3, /CRM/BW) used to retrieve data into portal iViews. We can create a System Object in any one of the three ways
 
The system object can be created from either of the following:
  • Based on System Template (Template)
  • Based on Portal Content      (PAR)
  • Coping Existing Systems     (System)
The Required Steps to Create a System Object in the portal are as :
  •           System Alias settings
  •         Connector settings
  •         ITS settings
  •         WAS settings
  •     User Management Settings

     
    Procedure to Create System Object in the Portal
  1. Login to the portal as Administrator.
  2.  Go to System Administration -> System Configuration -> System Landscape -> Browse -> Portal Content -> System landscape.          
     
  3. Right click on System landscape then select New in Context menu          
  4. Select System from template / from PAR, it will display Template Wizard
     
  5. Choose Template based on your Backend System either SAP or NON-SAP and click on the NEXT.
     
  6. Provide the General properties for this System Object (System name, ID, prefix, master language and description) and click on NEXT.
 
It will display the tab with System name and 3 radio button options.Select the default one is opens the object for editing and then selects the ok button. 
 
Now the name of the System name will appear under the System landscape folder in ->_Portal Content and with default display dropdown as Object and Property Category dropdown list as Showl All.
System Alias settings:
 
 In the display dropdown list select System Aliases, it display System Alias Editor, give Alias name generally CLNT ex: BI7CLNT100 and select the Add button and Save this properties by save button.
 


Connector settings:
 Select Object in the display dropdown list and then select Connector in the Property Category dropdown list and provide minimum connector properties for example  


ITS settings
 
 
ITS settings are maintained for displaying SAP transactions in the portal as an iViews.    Select Object in the display dropdown list and then select Internet Transaction Server (ITS) in the Property Category dropdown list and provide ITS properties as follows 

WAS settings
 
Web AS settings are required to display BW reports and for BSP applications in the Backend Systems such as CRM and BW/BI system.
 
Select Object in the display dropdown list and then select Web Application Server (WAS) in the Property Category dropdown list and provide  WAS properties as follows

User Management Settings
 
The following settings are required for user Management in the system object to connect to SAP backend systems.
 
Logon Method is either one of the following mechanisms
UIDPW                          -> when the PORTAL uses a user ID/PASSWORD as credentials.
SAPLOGONTICKET   -> PORTAL authenticating against the SAP backend system.
The X.509 certificate    -> PORTAL authenticating against the client certificates.   
                   
Note: Single Sign on (SSO) is required for SAP logon tickets and client certificates for SAP backend systems. 

User Mapping Type

The possible values for this property are Admin, User, and Admin/user.
 
User Mapping Type defines who can maintain the user mapping for the system.
 
If user mapping type is admin, only the administrator can maintain the user mapping.
 
If Type is User, only the end user can maintain the user mapping.
 
 
If Type is Admin/user is selected, both the administrator and the end user can maintain the user mapping.
  
Select Object in the display dropdown list and then select User Management in the Property Category dropdown list and fill User Management properties as follows    

Test the System Object

 
To logon to the portal as the common user in both portal and sap r3 system, and check the test connection whether the system object which you have created is successful or not.
 
Select the Connection Test in the display Dropdown list to test the connection with the

SAP R/3 backend system.


It displays system connection Tests screen in this select all check boxes and select the Test button.
 
If the test connection is successful it display the status column as green checks as shown above, otherwise it will display as red checks in this case please verify the connection properties like system alias, ITS, WAS and User Management properties.
 
P.S. : Taken from SCN SAP

Inherit KM Workflow steps from parent folder


Following is the code through which KM Workflow can inherit steps from Parent Folder
public boolean enableWorkflow(ICollection parentFolder,IResource childResource ) throws StatemanagementException, WcmException{
private static String NAMESPACE = "namespace.com";
private static String APP_PROPERTY_NAME = "Enable_Workflow";
boolean isWorkflowEnabled;
IPropertyName pname = PropertyName.getPN(NAMESPACE, APP_PROPERTY_NAME);
IProperty property = parentFolder.getProperty(pname);
if(null!=property){
isWorkflowEnabled=property.getBooleanValue();
}
IStatemanagementManager parentStateMgr =null;
IStatemanagementResource parentStateRes =null;
IStatemanagementUtilsResource parentStateResUtils = null;
IStepList parentStepList = null;
IStatemanagementResource childStateRes = null;
IStatemanagementUtilsResource childStateResUtils = null;
IApplicationPropertiesService appPropService = null;

IRepositoryServiceFactory repServiceFactory = ResourceFactory.getInstance().getServiceFactory();
IStatemanagementManager stateMgr = (IStatemanagementManager) repServiceFactory.getRepositoryService(childResource,IWcmConst.STATEMANAGEMENT_SERVICE);

if (isWorkflowEnabled) {
if (childResource.isCollection()) {
//set custom metadata property for child
childResource.setProperty(property);
//instantiate the statemanagement manager for parent
parentStateMgr = (IStatemanagementManager) repServiceFactory.getRepositoryService(parentFolder,IWcmConst.STATEMANAGEMENT_SERVICE);
//get the statemanagement resource for parent
parentStateRes = parentStateMgr.getStatemangementResource(parentFolder);
//get the statemanagement utils for parent
parentStateResUtils = parentStateRes.getUtils();
if(null != parentStateResUtils && parentStateResUtils.isStatemanagementEnabled()){
//read approver list
parentStepList = parentStateResUtils.readApproverList();
//get the statemanagement resource for child
childStateRes = stateMgr.getStatemangementResource(childResource);
//get the statemanagement utils instance for child resource
childStateResUtils = childStateRes.getUtils();
//enable workflow for child
childStateResUtils.setStatemanagementEnabled(true);
//add and save approver list for child
childStateResUtils.saveApproverList(parentStepList);
}else{return false;}
} else {
// setps to submit a not collection child resource for approval automatically
IStatemanagementResource sResource = stateMgr.getStatemangementResource(childResource);
IResourceTransitionList transitionList = sResource.getAllowedTransitions();
if (sResource.getUtils().readState().toString().equalsIgnoreCase("in progress")) {
IResourceTransition transition = sResource.getTransition("lbl.submit");
if(null != transition){
transition.execute();
}else{return false;}
}else{return false;}
}
}else{
return false;
}
return true;
}

Friday, June 15, 2012

Creating a resource in KM in SAP EP

Following is the Code to create any resource in Knowledge Management (KM)
propertyName = new PropertyName("http://sapportals.com/xmlns/cm","displayname");   
                   
//Creating the property map for the properties which needs to be   
//set for the KM resource being created.   
mutablePropertyMap = new MutablePropertyMap();   
  
//Creating the property and setting its display name   
mutableProperty = new MutableProperty(propertyName,"File");   
                   
//Populating the property map with the property created above.   
mutablePropertyMap.put(mutableProperty);   
                   
//Creating a resource(a file).   
resource = parent.createResource("SomeName.txt",mutablePropertyMap,null); 

Upload File into KM Repository

The report was generated in Excel file and stored in a shared drive location from where it was uploaded into the KM repository using KM API in Portal application.


//Create Excel Report in the Shared Drive
// trgtlocation is the location of the Excel report in the Shared drive
String trgtLocation ="C:\\Report\\Excel.xls";
File f = new File(trgtLocation);
//*******************************************//
// code to generate excel workbook and sheets excluded
//*******************************************//
try{
f.createNewFile();
workbook = Workbook.createWorkbook(f);
sheet = workbook.createSheet("First Sheet", 0);
}catch(Exception e){
}
File myExcel = new File("C:\\ Report\\Excel.xls");
InputStream myIS=new FileInputStream(myExcel);
IContent aContent = new Content(myIS,"byte",-1);
if(aCollection != null){
IResource aResource=( IResource)aCollection.createResource(Excel.xls,null,aContent);
myIS.close();
}//End of outer if
}catch(AccessDeniedException ex){
}
catch(NotSupportedException ex){
}
catch(ResourceException ex){
}

Extract PCD Objects from Portal

If their is any requirement where portal Administrator wants to see all the contents of Portal Content Directory and along with it wants to see Code Link (type of iView/System). They need to implement following code.


  1. Create a Par File.

    • Go to File -> New -> Other
    • Select Portal Application -> Create a Portal Application Project. -> Next
    • Give Project Name and pecify root folder path -> Finish
       
    • Again Right click on you project -> New -> Other
       
    • Select Portal Application -> Create a New Portal Application Object -> Next -> Next
       
    • Select AbstractPortalComponent  -> Next
       
    • Give Name, Location where you want to create this java file and package name. -> Finish
  2. Code:
    • Decalre following objects inside class .

    IiView iView = null;
    InitialContext ctx = null;
    DirContext dirCtx;
    IPcdContext context;
    List iViewList = null;
    String location = null;

    In DoContent Method write following code .

    InitialContext ctx = null;
    DirContext dirCtx;
    IPcdContext context;
    List iViewList = null;

    try
    {
     Hashtable env = new Hashtable();
     env.put(IPcdContext.SECURITY_PRINCIPAL, request.getUser());
     env.put(Context.INITIAL_CONTEXT_FACTORY, IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
     env.put(com.sap.portal.directory.Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);
     ctx = new InitialContext(env);

     dirCtx = (DirContext) ctx.lookup("pcd:portal_content/");
     PcdSearchControls pcdSearchControls = new PcdSearchControls();
     pcdSearchControls.setReturningObjFlag(false);
     pcdSearchControls.setSearchScope(pcdSearchControls.SUBTREE_WITH_UNIT_ROOTS_SCOPE);

     dirCtx.addToEnvironment(com.sap.portal.directory.Constants.APPLY_ASPECT_TO_CONTEXTS, com.sap.portal.directory.Constants.APPLY_ASPECT_TO_CONTEXTS);
    /*
                       
     NamingEnumeration ne_role = dirCtx.search("", "(com.sap.portal.pcd.gl.ObjectClass=com.sapportals.portal.role)",  pcdSearchControls); // for Role

     NamingEnumeration ne_page = dirCtx.search("", "(com.sap.portal.pcd.gl.ObjectClass=com.sapportals.portal.page)", pcdSearchControls); // for Page

         NamingEnumeration ne_system = dirCtx.search("", "(com.sap.portal.pcd.gl.ObjectClass=com.sapportals.portal.system)", pcdSearchControls); // forSystem
     
    */
     NamingEnumeration ne_iView = dirCtx.search("", "(com.sap.portal.pcd.gl.ObjectClass=com.sapportals.portal.iview)", pcdSearchControls);
     response.write("<table border='1'>\n");
     response.write("<tr><th>Location</th>\n");
     response.write("<th>Code Link</th></tr>\n");
     response.write("</br>");
     while (ne_role.hasMoreElements())
     {
     IPcdSearchResult searchResult = (IPcdSearchResult) ne_iView.nextElement();
     String location = "pcd:portal_content/" + searchResult.getName();
     ctx = new InitialContext(env);
     IiView result =  (IiView)ctx.lookup(location);
     String codelink =  result.getAttribute("CodeLink");
     response.write("<tr><td>"+location+ "</td>\n");
     response.write("<td>"+codelink+"</td>\n");
     }
    }

    catch(Exception e)
    {
    response.write("Exception Caught:"+e);
    }

  3. In portalapp.xml file under Application tab add following sharing references.

    com.sap.portal.pcm.admin.apiservice
    com.sap.portal.ivs.api_iview
    com.sap.portal.pcm.admin.apiservice

     
  4. Save and deploy on your portal. Run the application you will get the desired list in output.