cancel
Showing results for 
Search instead for 
Did you mean: 

Error while Uploading the docs into KM using webdynpro for java

Former Member
0 Kudos

In My view I have create a context node(ctx_va_FileData) with value attribute (ctx_va_FileResource) of type ,Resource.

Select the Simple Type, navigate to Dictionaries u2192 Local Dictionary u2192com.sap.ide.webdynpro.uielementdefinitions and select Resource.

In View part of Layout :Create one u201CFileUpload u201C UI with Create one LinkToAction IU element and assign u201CaUploadFileinto_KMu201D action to this action

Coding Part in Web Dynpro java

Step 1:

Go to the wdDoInit() method and paste the following code

public void wdDoInit()

{

//@@begin wdDoInit()

try {

IPrivateUploadFile_KMView.ICtx_vn_FileDataElement element = wdContext.createCtx_vn_FileDataElement();

if (element != null)

{

wdContext.nodeCtx_vn_FileData().bind(element);

}

}catch (Exception e) {

wdComponentAPI.getMessageManager().reportSuccess("Error: " + e.getCause().toString());

}

//@@end

}

Go to the onActionaUploadFileinto_KM and paste the following code

public void onActionaUploadFileinto_KM(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionaUploadFileinto_KM(ServerEvent)

msgMgr = wdComponentAPI.getMessageManager();

IPrivateUploadFile_KMView.ICtx_vn_FileDataElement element =

wdcontext.currentCtx_vn_FileDataElement();

IWDResource resource = element.getCtx_va_FileResource();

if(resource!=null){

try {

//To get the Current User

IWDClientUser wdClientUser = WDClientUser.getCurrentUser();

com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();

com.sapportals.portal.security.usermanagement.IUser ep5User =

WPUMFactory.getUserFactory().getEP5User(sapUser);

ResourceContext resourseContext = new ResourceContext(ep5User);

//Portal KM Path

RID pathRID = RID.getRID("/documents/SDN"); //Root Directory

IResourceFactory resourseFactory =

com.sapportals.wcm.repository.ResourceFactory.getInstance();

ICollection collection = (ICollection)resourseFactory.getResource(pathRID,

resourseContext);

//Read the File

InputStream stream = resource.read(true);

String resourceName = resource.getResourceName();

String resourceExtn = resource.getResourceType().getFileExtension();

//KM Content

Content cont = new Content(stream,"application/octet-stream",-1,"UTF-16");

//create a file in above mentioned path in KM

com.sapportals.wcm.repository.IResource new_resource =

(com.sapportals.wcm.repository.IResource)collection.

createResource(resourceName, null, cont);

//Get the File length

long contentLen = new_resource.getContent().getContentLength();

//If no data in file

if(contentLen <= 0){

msgMgr.reportException("No data in file" , true);

}else {

msgMgr.reportMessage(IMessageUploadFile_KMComp.SF__UPLOAD,

new Object[] {resourceName},true);

}

} catch (NotSupportedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (AccessDeniedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (WDUMException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (ResourceException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (ContentException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (UserManagementException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}else

msgMgr.reportException("No file Selected ,Browse the file!",true);

element.setCtx_va_FileResource(null);

}//End of Action

But in the onActionaUploadFileinto_KM part IUser is deprecated and i m stuck at that point.

Plz provide me the solution and is there ant alternative solution for this and MY Portal is EP6 Nwds version is 7.0.9

Accepted Solutions (1)

Accepted Solutions (1)

former_member214651
Active Contributor
0 Kudos

Hi,

try the following code:

IWDClientUser wdcu = WDClientUser.getCurrentUser();

StringTokenizer stkUserName = new StringTokenizer(wdcu.getClientUserID(),":");

while (stkUserName.hasMoreElements())

{

strUserID = stkUserName.nextToken();

}

Regards,

Poojith MV

Former Member
0 Kudos

Thanks guys for your kind help. I have implemented the same and got some good results.Although I am still not getting my desired result because of the lower version of SAP product that I am using.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Sukalyan,

Have you checked the below links?

These will give you step by step implementation procedure.

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a099a3bd-17ef-2b10-e6ac-9c1ea42af...

http://wiki.sdn.sap.com/wiki/display/WDJava/KmuploadusingWebdynproapplication

Regards,

Sandip