on 08-21-2007 3:38 PM
Hello,
For some business reason I have to run and test KM functionality from main method.
I need some examples
1. how to connect to KM,
2. how to create IUser and how to implement createUser method.
3. how to instantiate IResource
from main method.
Any Help Will be greatly appreciated ...
Hi Costa,
Prior to using the code, give reference to the following jar files in your build path using the PORTAL_HOME variable name.
bc.rf.framework_api.jar
bc.util.public_api.jar
com.sap.security.api.ep5.jar
prtapi.jar
Right click on your project, goto Properties > Web Dynpro References > Sharing References > Add > type <b>PORTAL:sap.com/com.sap.km.application</b>
You may use the following code to get connected to a folder in KM and to create an instance of IResource.
Assumption:
The folder name being SPAP under the documents folder in KM.
try {
IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
IUser sapUser = wdClientUser.getSAPUser();
com.sapportals.portal.security.usermanagement.IUser ep5User =
WPUMFactory.getUserFactory().getEP5User(sapUser);
ResourceContext context = new ResourceContext(ep5User);
RID rid = RID.getRID("/SPAP");
IResourceFactory factory = ResourceFactory.getInstance();
//get an instance of the current folder under which we have to create subfolders
ICollection folder = (ICollection) factory.getResource(rid, context);
ICollection newfolder = folder.createCollection(wdContext.currentContextElement().getQNtest(),null,null);
// To get a resource from a folder
//Assumption: template being the file under SPAP folder
RID templateRID =RID.getRID("/SPAP/template");
IResourceFactory fileFactory = ResourceFactory.getInstance();
IResource templateResource =fileFactory.getResource(templateRID, context);
//To create an instance of IResource
//Assumption: We have a byte[] <b>inBytes</b> which corresponds to the content of a PDF/any file.
ByteArrayInputStream dataStream = new ByteArrayInputStream(inBytes);
//getting content
IContent getContent = new Content(dataStream, "text/XML", dataStream.available());
RID rid = RID.getRID("/SPAP");
IResourceFactory factory = ResourceFactory.getInstance();
IResource resource = factory.getResource(rid, context);
ICollection folder = (ICollection) factory.getResource(rid, context);
//"template" is nothing but the name of the resource that we are trying to create
IResource resourceNew = folder.createResource("template", null, getContent);
} catch (Exception e) {
// wdContext.currentContextElement().setTest(e.getMessage());
}
Can you tell me why you want to create a user using IUser API?
As you are deploying the code on your J2EE engine using the SDM user ID and password, it should take that authentication and access the KM folder in EP.
Hope this helps.
Regards,
Rekha Malavathu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.