on 11-19-2014 7:17 AM
Dear All
I have a requirement for client.Here 2 types of users available.User one upload the documents in KM using the WDJ application and same time that user can create the sub folder.once that folder is available in that upload the documents.This user is a admin type.An other user can see the document by using the WDJ application. this user is end user type and Read only.
->My question is by using the WDJ application to upload and download and creating the folders or sub folders in run time process.
I was checked this blow links but i am unable to get the information.
Please any Code /Document available means share me.
Thank for advance,
BR,
Durga Rao.
hi Durga rao,
File upload :
try {
IPrivateCompView.ICtx_vn_FileDataElement element = wdContext.currentCtx_vn_FileDataElement();
IWDResource resource = element.getCtx_va_FileResource();
if(resource!=null){
//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/Links"); //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();
wdContext.currentContextElement().setFileName(resourceName);
wdContext.currentZep_Sug_Submit_InputElement().setAttachment(resourceName);
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 =collection.createResource(resourceName, null, cont);
//Get the File length
long contentLen = new_resource.getContent().getContentLength();
//If no data in file
if(contentLen <= 0){
wdComponentAPI.getMessageManager().reportException("No data in file" , true);
}else {
// wdComponentAPI.getMessageManager().reportMessage(IMessageUploadFile_KMComp.SF__UPLOAD,new Object[] {resourceName},true);
}
}else{
element.setCtx_va_FileResource(null);
}
}catch (Exception e) {
wdComponentAPI.getMessageManager().reportSuccess(""+e.getMessage());
//wdComponentAPI.getMessageManager().reportWarning(e.printStackTrace());
// TODO: handle exception
}
File Download :
IWDClientUser wdClientUser;
try {
wdClientUser = WDClientUser.getCurrentUser();
IUser sapUser = wdClientUser.getSAPUser();
com.sapportals.portal.security.usermanagement.IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);
//Getting the Resource.........
IResourceContext resourseContext = new ResourceContext(ep5User);
//wdComponentAPI.getMessageManager().reportSuccess("resourseContext"+resourseContext);
IResourceFactory resourseFactory = ResourceFactory.getInstance();
//wdComponentAPI.getMessageManager().reportSuccess("resourseFactory"+resourseFactory);
//path to the KM Folder ("/documents/Alice In Wonderland/alice.gif")
RID pathRIDimg = RID.getRID(path);
if(wdContext.currentOutputElement().getAttachment() != null){
if((null != pathRIDimg )&&(null != resourseContext))
{
IResourceFactory factory = com.sapportals.wcm.repository.ResourceFactory.getInstance();
com.sapportals.wcm.repository.IResource resource = factory.getResource(pathRIDimg, resourseContext);
// wdComponentAPI.getMessageManager().reportSuccess("resourceimg :"+resource);
String s = path;
String result = s.substring(s.lastIndexOf('.')+1).trim();
BufferedInputStream bufIn = new BufferedInputStream(resource.getContent().getInputStream());
IWDCachedWebResource cachedWebResource = null;
if(result.equalsIgnoreCase("xlsx")){
cachedWebResource = WDWebResource.getWebResource(bufIn, WDWebResourceType.XLSX);
String url = cachedWebResource.getUrl(WDFileDownloadBehaviour.ALLOW_SAVE.ordinal()) ;
wdContext.currenDetailsElement().setDoc_link(url);
}
The above worked code worked perfectly for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Anil,
Thanks for the Reply.
I checked file upload is working fine.But i want to create the folder in the KM in that folder i need to upload the files ,this process should be though code.once the folder is there the upload files need to save .Other wise need to create the folder.same process to get the download files also.
Please help me.
Regards,
Durga Rao.
Hi Durga Rao,
for creating a folder in the KM pragmatically use the below code,
try {
IWDClientUser WDClientUser = WDClientUser.getCurrentUser();
com.sap.security.api.IUser sapUser = WDClientUser.getSAPUser();
com.sapportals.portal.security.usermanagement.IUser epUser = WPUMFactory.getUserFactory().getEP5User(sapUser);
// wdComponentAPI.getMessageManager().reportSuccess(epUser.toString());
IResourceContext context = new ResourceContext(epUser);
RID rid = RID.getRID(“/documents”);
ICollection parent = (ICollection)ResourceFactory.getInstance().getResource(rid, context);
IResource resource = parent.createResource(“file”, null, null);
ICollection collection = parent.createCollection(“folder”, null);
wdComponentAPI.getMessageManager().reportSuccess(“uploaded”);
//ILink link = parent.createLink(″link″, ″/documents/file″, LinkType.INTERNAL, null);
} catch (ResourceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WDUMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UserManagementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.