cancel
Showing results for 
Search instead for 
Did you mean: 

Get a document from the KM repository

Former Member
0 Kudos

Hi,

I have a web dynpro that gives the user the option to download a PDF document. This PDF document is stored under the project "src" directory. Now I have to make the PDF available even outside the webdynpro as a link inside the Employee Self Service. In order to do this, I'll add the PDF inside a subdirectory of the KM repository and I'll create a KM document iView in order to show it as a link into the ESS.

My question is:

in order to avoid having duplicates (one PDF inside the Web Dynpro and one PDF inside the KM repository) is there a way:

1) to get a KM document from the WebDynpro

OR

2) to create an iView that points to the document stored inside the WebDynpro

If both are possible, I'd prefer the first one... in that way I won't have to recompile the WD every time the project changes.

Thank you,

Pietro

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Pietro,

It is very much possible to get the documents from KM, in Web Dynpro applications.

If you are working in NWDS 7.0, you will get KM APIs to access the KM. By adding these APIs (JAR files) to your Webdynpro DC or project's build path, you will be able to access the methods to read the file.

Step1: Add the below JARs into the build path (you can find these in the plugin folder)

bc.rf.framework_api.jar

bc.rf.global.service.notificator_api.jar

bc.sf.framework_api.jar

bc.util.private_api.jar

bc.util.public_api.jar

com.sap.security.api.ep5.jar

com.sap.security.api.ep5.jar

Step2: Add the sharing reference PORTAL:sap.com/com.sap.km.application in Web dynpro References.

Step3: Write the below code in the download method


com.sapportals.portal.security.usermanagement.IUser user =
	WPUMFactory.getServiceUserFactory().getServiceUser("Service user ID"); // You can get the service user info from the portal admin
IResourceContext rCtx = new ResourceContext(user);
RID data= RID.getRID("Relative Path"+"/Article.pdf"); //Say "/root/documents/etc/Article.pdf" if the file is stored under etc folder
IResource resource = ResourceFactory.getInstance().getResource(data, rCtx);
if(resource != null)
{
IContent cont = resource.getContent();
InputStream inputStream = cont.getInputStream();  
}

From the input stream you can extract the file and open it.

Regards,

Vishweshwara P.K.M.

Former Member
0 Kudos

Hi Vishweshwara,

yes, I'm using Netweaver 7.0. I'm having trouble finding the dependencies to add to my WebDynpro's Used DCs.

Can you tell me which Software Components and which development components to add to my WD?

Thank you,

Pietro

Former Member
0 Kudos

Hi Pietro,

You need not add your DC to any SC. Just search for the api by name and add it to your DCs depedencies.

Regards,

Vishweshwara P.K.M.

Former Member
0 Kudos

HI Vishweshwara,

I've set up the project as you described.

=======EDIT======

Now what I really need is just the URL of the resource, because my code continues as follows:

		IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow(
			resource.getUrl(0), "Download file", true);

So what I really need is to have the complete URL to put in substitution of resource.getUrl(0).

Is there a way to get it without having to create a ResourceContext? I'm asking because I don't know how to reuse the IResource that I get in the end.

If there is a way to get the server base url (e.g.: https://test.myserver.com/) i could append to it the relative path hardcoded into my Web Dynpro (e.g.: "/root/documents/Public Documents/..." or the path that Jacek suggested ("/irj/go/km/docs/...").

================

Can you help me?

Thank you,

Pietro

Edited by: pietro m. on Mar 5, 2012 6:23 PM

Sreejith1
Contributor
0 Kudos

Hi,

If you are trying to access file from Km, it is not possible to use direct link.Youmust use the resource path.

Former Member
0 Kudos

Hi Pietro,

To access the documents from KM you need to get the IResourceContext and do the stuf I had earlier mentioned.

once you get the inputstream as explained in my earlier post you can use the below code to generate the URL and open it in a new window.


WDWebResourceType resourceType = WDWebResourceType.getWebResourceType("application/pdf", "PDF");//For files of type PDF only. For other types of files you should use corresponding MIME type.
IWDResource resource = WDResourceFactory.createResource(inputStream, "FileName", resourceType, true);
if(resource != null){
       String url = resource.getUrl(0);
       IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow(url, "Download file", true);
}

Regards,

Vishweshwara P.K.M.

Former Member
0 Kudos

Hi Vishweshwara,

thank you for your kind help.

Concerning the JARs that you told me to add to the build path, I've added them but when I build the project on the server the build fails because the CBS can't find the JARs.

I've tried to move them into the lib directory of the WebDynpro to no avail.

Here is the error message that I've got:

[javac] ERROR: E:\Pietro\Workspaces\Netweaver HR DTC\0\t\3211C3CC33F31D79B9D2ECAC85EDCB14\gen_wdp\packages\com\bi\macont\RichView.java:28: package com.sapportals.wcm.repository does not exist
     [javac] ERROR: import com.sapportals.wcm.repository.IResource;
     [javac] ERROR:                                      ^

Can you suggest me anything about this?

Thank you,

Pietro

junwu
Active Contributor
0 Kudos

if your project is created as DC, add jar in build path will have no effect.

you have to add dependency to the dc which contains the jar.

Former Member
0 Kudos

Hi,

Identify the DC where IResource belong and add the DC as a dependency in your DC.

Have a look to this Link: [http://help.sap.com/saphelp_nw72/helpdata/en/49/11e3d5cf292810e10000000a42189c/content.htm]

Some more info about KM repository: Link: [http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/aef1a890-0201-0010-6faf-8fa094808653?QuickLink=index&overridelayout=true]

Best regards,

David.

Edited by: david.ruizdeazua on Mar 7, 2012 11:41 AM

Former Member
0 Kudos

Hi Pietro,

Sorry, I had assumed that you are working on a local project.

If you are working on a DC in NWDI, then you should be adding these JAR files into an external Library DC, create Public parts in that library DC and add these JAR files to the public part. Then add these public parts into your web dynpro DC. Now your problem should be solved.

Hope you know how to create external library and use its public parts in web dynpro DC.

Regards,

Vishweshwara P.K.M.

Former Member
0 Kudos

Hi Vishweshwara,

I've tried several procedures found online to create the External Library without success.

I get always the same build error as if the DC does not see the External Library's JAR files.

I don't know what to add in the Properties\Webdynpro Reference\Library Reference section of my DC.

I have the jar names. Do I have to put them there?

Thank you,

Pietro

Answers (1)

Answers (1)

wozjac
Product and Topic Expert
Product and Topic Expert
0 Kudos

1) to get a KM document from the WebDynpro

You can get it directly via relative url /irj/go/km/docs/kmfolder/document.pdf.

Edited by: jacek wozniczak on Mar 5, 2012 2:57 PM

Former Member
0 Kudos

Hi Jacek,

this seems an easier approach.

I'll try it.

Former Member
0 Kudos

Hi Jacek,

I've used these lines of code to load the PDF stored under the "src" folder:

		InputStream stream = getClass().getResourceAsStream(
			fileRichiesta);
		IWDResource resource = WDResourceFactory.createResource(
			stream, nomeRichiesta, WDWebResourceType.PDF, true);	
		stream.close();

where fileRichiesta is the string variable that hosts the relative path.

I've tried to put the path you gave me, replacing kmfolder with the relative path and document.pdf with the file name, but it doesn't work because I get an InputStream exception. I've tried opening the URL with the Browser and it works fine.

Can you help me?

Thank you,

Pietro

Qualiture
Active Contributor
0 Kudos

Hi Pietro

If my memory serves me well, I believe only FileInputStream accepts relative paths

wozjac
Product and Topic Expert
Product and Topic Expert
0 Kudos

Pietro,

there might be some issues with authorization - when I tried this with URL class and then opened a stream from URL I got HTTP 401.

Perhaps you should find other way - my case is suitable for ie. LinkToURL. Or try with passing some auth info to URL class.

Regards,

Jacek