Quantcast
Channel: SCN : All Content - Web Dynpro Java
Viewing all articles
Browse latest Browse all 1288

Get the File/Folder/Link information form KM repository by using Webdynpro JAVA

$
0
0

Hello Friends,

 

 

This document follows, how to Read the file infomation from the KM Repository by using Webdynpro JAVA

 

Get the File/Folder/Link(Name,Discription,Size,CreatedBy(userName,Date),ModifiedBy(userName,Date),Keywords,Information,Owner,MIME Type,Path and ShortID) information form KM repository by using Webdynpro JAVA

 

Get the File/Folder/Link information form KM repository by using Webdynpro JAVA

  1. Agenda: -

This document explores the Name,Discription,Size,CreatedBy(userName,Date),ModifiedBy(userName,Date),Keywords,Information,Owner,MIME Type, Path and Short-ID form KM repository by using Webdynpro JAVA

 

Below Screen shoots for the Required Output Information

1.JPG

2.JPG

3.JPG

 

Output Structure by using Webdynpro JAVA

4.JPG

2. Context:-

5.JPG

Under UpdateList value Node all Value Attributes data type is String and checkKMResource data type is Boolean.

Under FolderContent  HasChildren and isExpand data type is Boolean and remaining all Data type is String

 

How to Create Tree Structure:-

 

7.JPG

Table Structure in Webdynpro JAVA Application

6.JPG

 

Codeing Part in Webdynpro JAVA

  // ---------------------------------------------------------------------------

// This file has been generated partially by the Web Dynpro Code Generator.

// MODIFY CODE ONLY IN SECTIONS ENCLOSED BY @@begin AND @@end.

// ALL OTHER CHANGES WILL BE LOST IF THE FILE IS REGENERATED.

// ---------------------------------------------------------------------------

package com.corp.iview.i_v_kmfoldertreeview.com;

//

// IMPORTANT NOTE:

// _ALL_ IMPORT STATEMENTS MUST BE PLACED IN THE FOLLOWING SECTION ENCLOSED

// BY @@begin imports AND @@end. FURTHERMORE, THIS SECTION MUST ALWAYS CONTAIN

// AT LEAST ONE IMPORT STATEMENT (E.G. THAT FOR IPrivateV_kmFolderTreeView).

// OTHERWISE, USING THE ECLIPSE FUNCTION "Organize Imports" FOLLOWED BY

// A WEB DYNPRO CODE GENERATION (E.G. PROJECT BUILD) WILL RESULT IN THE LOSS

// OF IMPORT STATEMENTS.

//

//@@begin imports

//import com.corp.iview.i_v_kmfoldertreeview.com.wdp.IPrivateV_kmFolderTreeView;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import java.io.InputStream;

import java.text.DecimalFormat;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Date;

import java.util.LinkedHashMap;

import java.util.List;

import java.util.Map;

import com.sap.tc.webdynpro.clientserver.uielib.standard.api.IWDTreeNodeType;

import com.sap.tc.webdynpro.progmodel.api.IWDMessageManager;

import com.sap.tc.webdynpro.progmodel.api.WDVisibility;

import com.sap.tc.webdynpro.services.sal.adapter.api.IWDRequest;

import com.sap.tc.webdynpro.services.sal.adapter.api.WDProtocolAdapter;

import com.sap.tc.webdynpro.services.sal.um.api.IWDClientUser;

import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser;

import com.sapportals.portal.security.usermanagement.IUser;

import com.sapportals.wcm.repository.ICollection;

import com.sapportals.wcm.repository.IProperty;

import com.sapportals.wcm.repository.IPropertyName;

import com.sapportals.wcm.repository.IResource;

import com.sapportals.wcm.repository.IResourceContext;

import com.sapportals.wcm.repository.IResourceFactory;

import com.sapportals.wcm.repository.IResourceList;

import com.sapportals.wcm.repository.IResourceListIterator;

import com.sapportals.wcm.repository.PropertyName;

import com.sapportals.wcm.repository.ResourceContext;

import com.sapportals.wcm.repository.ResourceFactory;

import com.sapportals.wcm.repository.ResourcePropertyComparator;

import com.sapportals.wcm.repository.manager.IAclSecurityManager;

import com.sapportals.wcm.repository.manager.ISecurityManager;

import com.sapportals.wcm.repository.security.IResourceAcl;

import com.sapportals.wcm.repository.security.IResourceAclEntry;

import com.sapportals.wcm.repository.security.IResourceAclEntryListIterator;

import com.sapportals.wcm.repository.security.IResourceAclManager;

import com.sapportals.wcm.service.IServiceTypesConst;

import com.sapportals.wcm.service.urimapper.IUriMapperService;

import com.sapportals.wcm.service.urlgenerator.IURLGeneratorService;

import com.sapportals.wcm.service.urlgenerator.PathKey;

import com.sapportals.wcm.util.content.IContent;

import com.sapportals.wcm.util.uri.IUriReference;

import com.sapportals.wcm.util.uri.RID;

import com.sapportals.wcm.util.usermanagement.WPUMFactory;

import com.corp.comp.co_kmfoldertree.com.wdp.IMessageCO_kmFolderTree;

import com.corp.iview.i_v_kmfoldertreeview.com.wdp.IPrivateV_kmFolderTreeView;

import com.corp.iview.i_v_kmfoldertreeview.com.wdp.IPrivateV_kmFolderTreeView.IFolderContentElement;

import com.corp.iview.i_v_kmfoldertreeview.com.wdp.IPrivateV_kmFolderTreeView.IFolderContentNode;

import com.corp.iview.i_v_kmfoldertreeview.com.wdp.IPrivateV_kmFolderTreeView.IUpdateListElement;

  

  

//@@end

//@@begin documentation

//@@end

publicclass V_kmFolderTreeView

{

/**

*Logginglocation.

*/

privatestaticfinal com.sap.tc.logging.Location logger =

  1. com.sap.tc.logging.Location.getLocation(V_kmFolderTreeView.class);

static

{

//@@begin id

String id = "$Id$";

//@@end

  1. com.sap.tc.logging.Location.getLocation("ID.com.sap.tc.webdynpro").infoT(id);

}

/**

*PrivateaccesstothegeneratedWebDynprocounterpart

*forthiscontrollerclass.</p>

*

*Use<code>wdThis</code>togaintypedaccesstothecontext,

*totriggernavigationviaoutboundplugs,togetandenable/disable

*actions,firedeclaredevents,andaccessusedcontrollersand/or

*componentusages.

*

*@seecom.corp.iview.i_v_kmfoldertreeview.com.wdp.IPrivateV_kmFolderTreeViewformoredetails

*/

privatefinal IPrivateV_kmFolderTreeView wdThis;

/**

*Rootnodeofthiscontroller'scontext.</p>

*

*Providestypedaccessnotonlytotheelementsoftherootnode

*butalsotoallnodesinthecontext(methodsnode<i>XYZ</i>())

*andtheircurrentlyselectedelement(methodscurrent<i>XYZ</i>Element()).

*Italsofacilitatesthecreationofnewelementsforallnodes

*(methodscreate<i>XYZ</i>Element()).</p>

*

*@seecom.corp.iview.i_v_kmfoldertreeview.com.wdp.IPrivateV_kmFolderTreeView.IContextNodeformoredetails.

*/

privatefinal IPrivateV_kmFolderTreeView.IContextNode wdContext;

/**

*Ashortcutfor<code>wdThis.wdGetAPI()</code>.</p>

*

*RepresentsthegenericAPIofthegenericWebDynprocounterpart

*forthiscontroller.</p>

*/

privatefinal com.sap.tc.webdynpro.progmodel.api.IWDViewController wdControllerAPI;

/**

*Ashortcutfor<code>wdThis.wdGetAPI().getComponent()</code>.</p>

*

*RepresentsthegenericAPIoftheWebDynprocomponentthiscontroller

*belongsto.Canbeusedtoaccessthemessagemanager,thewindowmanager,

*toadd/removeeventhandlersandsoon.</p>

*/

privatefinal com.sap.tc.webdynpro.progmodel.api.IWDComponent wdComponentAPI;

public V_kmFolderTreeView(IPrivateV_kmFolderTreeView wdThis)

{

  1. this.wdThis = wdThis;
  2. this.wdContext = wdThis.wdGetContext();
  3. this.wdControllerAPI = wdThis.wdGetAPI();
  4. this.wdComponentAPI = wdThis.wdGetAPI().getComponent();

}

//@@begin javadoc:wdDoInit()

/**Hookmethodcalledtoinitializecontroller.*/

//@@end

publicvoid wdDoInit()

{

//@@begin wdDoInit()

initializeRepositoryTree();

//@@end

}

//@@begin javadoc:wdDoExit()

/**Hookmethodcalledtocleanupcontroller.*/

//@@end

publicvoid wdDoExit()

{

//@@begin wdDoExit()

//@@end

}

//@@begin javadoc:wdDoModifyView

/**

*Hookmethodcalledtomodifyaviewjustbeforerendering.

*Thismethodconceptuallybelongstotheviewitself,nottothe

*controller(cf.MVCpattern).

*Itismadestatictodiscourageawayofprogrammingthat

*routinelystoresreferencestoUIelementsininstancefields

*foraccessbytheviewcontroller'seventhandlers,andsoon.

*TheWebDynproprogrammingmodelrecommendsthatUIelementscan

*onlybeaccessedbycodeexecutedwithinthecalltothishookmethod.

*

*@paramwdThisGeneratedprivateinterfaceoftheview'scontroller,as

*providedbyWebDynpro.Providesaccesstotheviewcontroller's

*outgoingcontrollerusages,etc.

*@paramwdContextGeneratedinterfaceoftheview'scontext,asprovided

*byWebDynpro.Providesaccesstotheview'sdata.

*@paramviewTheview'sgenericAPI,asprovidedbyWebDynpro.

*ProvidesaccesstoUIelements.

*@paramfirstTimeIndicateswhetherthehookiscalledforthefirsttime

*duringthelifetimeoftheview.

*/

//@@end

publicstaticvoid wdDoModifyView(IPrivateV_kmFolderTreeView wdThis, IPrivateV_kmFolderTreeView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

//@@begin wdDoModifyView

if (firstTime) {

IWDTreeNodeType treeNode = (IWDTreeNodeType) view.getElement("treeNodeKMNav");

  1. treeNode.mappingOfOnAction().addSourceMapping("path","elementSelection");
  2. treeNode.mappingOfOnLoadChildren().addSourceMapping("path", "element");

}

//@@end

}

//@@begin javadoc:get_child_resources()

/**Declaredmethod.*/

//@@end

publicvoid get_child_resources( java.lang.String tempResource )

{

//@@begin get_child_resources()

addEntriesToUpdateList(tempResource);

//@@end

}

//@@begin javadoc:onActionshowHideTree(ServerEvent)

/**Declaredvalidatingeventhandler.*/

//@@end

publicvoid onActionshowHideTree(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionshowHideTree(ServerEvent)

if (wdContext.currentUpdateElement().getTreeShow() == WDVisibility.VISIBLE) {

  1. wdContext.currentUpdateElement().setCollapseIcon("~sapicons/s_b_pagr.gif");
  2. wdContext.currentUpdateElement().setTreeShow(WDVisibility.NONE);

} else {

  1. wdContext.currentUpdateElement().setCollapseIcon("~sapicons/s_b_pagl.gif");
  2. wdContext.currentUpdateElement().setTreeShow(WDVisibility.VISIBLE);

}

//@@end

}

//@@begin javadoc:onActionNodeSelection(ServerEvent)

/**Declaredvalidatingeventhandler.*/

//@@end

publicvoid onActionNodeSelection(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.corp.iview.i_v_kmfoldertreeview.com.wdp.IPrivateV_kmFolderTreeView.IFolderContentElement elementSelection )

{

//@@begin onActionNodeSelection(ServerEvent)

  1. wdContext.currentUpdateElement().setInputEnabled(true);
  2. wdContext.currentUpdateElement().setFolderPath(elementSelection.getPath());

// wdComponentAPI.getMessageManager().reportSuccess("Path:-"+elementSelection.getPath());

  1. wdContext.nodeUpdateList().invalidate();
  2. wdContext.nodeUpdateList().clearSelection();

//@@end

}

//@@begin javadoc:onActionLoadChildren(ServerEvent)

/**Declaredvalidatingeventhandler.*/

//@@end

publicvoid onActionLoadChildren(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.corp.iview.i_v_kmfoldertreeview.com.wdp.IPrivateV_kmFolderTreeView.IFolderContentElement element )

{

//@@begin onActionLoadChildren(ServerEvent)

addChildren(element);

//@@end

}

//@@begin javadoc:onActionfindOnly(ServerEvent)

/**Declaredvalidatingeventhandler.*/

//@@end

publicvoid onActionfindOnly(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionfindOnly(ServerEvent)

// For Find Only (no Replace) we only need to confirm

  1. wdContext.nodeUpdateList().invalidate();

// wdComponentAPI.getMessageManager().reportSuccess("Path:"+wdContext.currentUpdateElement().getFolderPath());

addEntriesToUpdateList(wdContext.currentUpdateElement().getFolderPath());

  1. wdComponentAPI.getMessageManager().reportSuccess("Search Complete");

//wdContext.nodeUpdateList().setLeadSelection(-1);

//@@end

}

//@@begin javadoc:onActionexportExcel(ServerEvent)

/**Declaredvalidatingeventhandler.*/

//@@end

publicvoid onActionexportExcel(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionexportExcel(ServerEvent)

// wdThis.wdGetCO_kmFolderTreeController().downloadData(wdContext.nodeUpdateList());

  1. wdThis.wdGetCO_kmFolderTreeController().Export_to_excel(getKMResourceColumnInfos(),wdContext.nodeUpdateList());

//@@end

}

//@@begin javadoc:onActiongetChild_KM_ResourceFiles(ServerEvent)

/**Declaredvalidatingeventhandler.*/

//@@end

publicvoid onActiongetChild_KM_ResourceFiles(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActiongetChild_KM_ResourceFiles(ServerEvent)

boolean getKMResource = false;

if(wdContext.currentUpdateListElement().getCheckKMResource() == false)

{

addEntriesToUpdateList(wdContext.currentUpdateListElement().getFilePath());

  1. wdContext.currentUpdateListElement().setCheckKMResource(true);

}else

{

  1. wdComponentAPI.getMessageManager().reportWarning("KM Resource Files already avaliable in Table");

}

  1. wdContext.nodeUpdateList().setLeadSelection(-1);

//@@end

}

//@@begin javadoc:onActionReadFile(ServerEvent)

/**Declaredvalidatingeventhandler.*/

//@@end

publicvoid onActionReadFile(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionReadFile(ServerEvent)

//@@end

}

/*

* The following code section can be used for any Java code that is

* not to be visible to other controllers/views or that contains constructs

* currently not supported directly by Web Dynpro (such as inner classes or

* member variables etc.). </p>

*

* Note: The content of this section is in no way managed/controlled

* by the Web Dynpro Designtime or the Web Dynpro Runtime.

*/

//@@begin others

privatevoid addChildren(IFolderContentElement parent)

{

IFolderContentNode folderContentNode = parent.nodeChildNode();

IFolderContentElement folderContentElement;

boolean hasChildren = false;

try {

// Get a Resouce Context from the Local Method

IResourceContext resourceContext = buildResourceContext();

// get a resource factory

IResourceFactory resourceFactory = ResourceFactory.getInstance();

// Get a RID from the current path to display the according content

RID pathRID = RID.getRID(parent.getPath());

// Get a Iresource object to work on

IResource resource = resourceFactory.getResource(pathRID, resourceContext);

// cast the object to a Collection

ICollection collection = (ICollection) resource;

// get the Collection's Children

IResourceList resourceList = collection.getChildren();

// Sort Resource List by Name (Local Method)

sortResouceListByName(resourceList);

// Finally get an iterator to walk through the set of Children

IResourceListIterator resourceListIterator = resourceList.listIterator();

// Now read all elements

while (resourceListIterator.hasNext()) {

IResource tempResource = resourceListIterator.next();

if (tempResource.isCollection()) {

// create a new Context element for each of them

folderContentElement = folderContentNode.createFolderContentElement();

// Local Method

addFolderToContextNode(folderContentElement, tempResource, pathRID);

  1. folderContentNode.addElement(folderContentElement);
  2. parent.setIsExpand(true);

hasChildren = true;

}

}if (!hasChildren) {

  1. parent.setHasChildren(false);

}

} catch (Exception e) {

  1. e.printStackTrace();

}

}

privatevoid addFolderToContextNode(IFolderContentElement element, IResource tempResource, RID pathRID) throws Exception {

// Entry is a Folder

  1. element.setHasChildren(true);
  2. element.setIconSource("~sapicons/s_clofol.gif");

// Use the Name if the DisplayName is Blank

if (tempResource.getDisplayName() == "") {

  1. element.setText(tempResource.getName());

} else {

  1. element.setText(tempResource.getDisplayName());

}

// Create another RID for the directory that shall be opened

RID directoryToOpenRID;

// If the current directory is the root..

if (pathRID.isRoot()) {

directoryToOpenRID =

  1. RID.getRID(pathRID.toString() + tempResource.getName());

} else {

directoryToOpenRID = RID.getRID(pathRID.toString() + "/" + tempResource.getName());

}

// set the selected directory as the new path

  1. element.setPath(directoryToOpenRID.toString());
  2. element.setIsExpand(false);

}

private IResourceContext buildResourceContext() throws Exception {

// create an user object from the current user

IWDClientUser wdClientUser = WDClientUser.getCurrentUser();

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

// Create a EP user from the retrieved user

IUser epUser = WPUMFactory.getUserFactory().getEP5User(sapUser);

// Establish a Resource Context

IResourceContext resourceContext = new ResourceContext(epUser);

return resourceContext;

}

privatevoid sortResouceListByName(IResourceList resourceList)

throws Exception {

// create property names to index properties

IPropertyName iPropSort = new PropertyName("http://sapportals.com/xmlns/cm", "displayname");

// create a comparator to order the resource list

ResourcePropertyComparator rRPC =

new ResourcePropertyComparator(iPropSort, true);

// order the resource list

  1. resourceList.sort(rRPC); }

privatevoid initializeRepositoryTree() {

IFolderContentNode rootFolderContentNode = wdContext.nodeFolderContent();

IFolderContentElement rootFolderContentElement;

rootFolderContentElement = rootFolderContentNode.createFolderContentElement();

  1. rootFolderContentElement.setPath("/documents/Another FolderName/Folder View");
  2. rootFolderContentElement.setIsExpand(true);
  3. rootFolderContentElement.setText("/Folder View");
  4. rootFolderContentElement.setHasChildren(true);
  5. rootFolderContentElement.setIconSource("~sapicons/s_clofol.gif");
  6. rootFolderContentNode.addElement(rootFolderContentElement);

addChildren(rootFolderContentElement);

}

private String generateUrlForResource(IResource resource) throws Exception {

// Generate URL for a Resource

IURLGeneratorService ug = (IURLGeneratorService) ResourceFactory.getInstance().getServiceFactory().getService(IServiceTypesConst.URLGENERATOR_SERVICE);

IUriReference uriRef2;

uriRef2 = ug.getRelativeUri(PathKey.CONTENT_ACCESS_PATH).appendPath(resource.getRID().toExternalForm());

return uriRef2.toExternalForm();

}

privatevoid addEntriesToUpdateList(String path)

{

// wdComponentAPI.getMessageManager().reportSuccess("path:-"+path);

IUpdateListElement updateListElement;

try

{

IUser serviceUser = (IUser)WPUMFactory.getServiceUserFactory().getServiceUser(Admin_Service_User);

IResourceFactory resourceFactory = ResourceFactory.getInstance(); //IResourceFactory factory

IResourceContext resourceContext = new ResourceContext(serviceUser); //IResourceContext context

// IResourceContext resourceContext = buildResourceContext(serviceUser);

// IResourceFactory resourceFactory = ResourceFactory.getInstance();

RID pathRID = RID.getRID(path);

// wdComponentAPI.getMessageManager().reportSuccess("pathRID:-"+pathRID);

IResource resource = resourceFactory.getResource(pathRID, resourceContext);

if(resource.isCollection())

{

ICollection collection = (ICollection) ResourceFactory.getInstance().getResource(pathRID,(IResourceContext) resourceContext);

IResourceList resourceList = null;

if (null != collection)

{

resourceList = collection.getChildren();

//wdComponentAPI.getMessageManager().reportSuccess("Resource Size:"+collection.getChildren().size());

}// end null != collection

else

{

  1. wdComponentAPI.getMessageManager().reportSuccess("Error");

}

// wdComponentAPI.getMessageManager().reportSuccess("resource List "+resourceList);

IResourceListIterator resourceListIterator =resourceList.listIterator();

// wdComponentAPI.getMessageManager().reportSuccess("resourceListIterator: "+resourceListIterator);

// List listofDirs=new ArrayList();

int i=0;

while (resourceListIterator.hasNext())

{

IResource tempResource = resourceListIterator.next();

//wdComponentAPI.getMessageManager().reportSuccess("tempResource "+tempResource);

// wdComponentAPI.getMessageManager().reportSuccess("tempResource.isCollection() "+tempResource.isCollection());

if (tempResource.isCollection() || !tempResource.isCollection())

{

// addEntriesToUpdateList(path);

updateListElement = wdContext.nodeUpdateList().createUpdateListElement();

  1. updateListElement.setFilePath(path);

//get ResourceName

if (tempResource.getDisplayName() == ""&& (tempResource.getDisplayName()!=null || tempResource.getDisplayName()==null))

{

  1. updateListElement.setFileName(tempResource.getName());

}else

{

  1. updateListElement.setFileName(tempResource.getDisplayName());

}

// get Discription

if(tempResource.getDescription()!=null || tempResource.getDescription()==null){

  1. updateListElement.setFileDiscription(tempResource.getDescription());

}

// get ResourceType

if(tempResource.getTargetURL()==null){

if(tempResource.getContent().getContentType() != null&& tempResource.getContent().getContentType() != ""){

  1. updateListElement.setResourceType("File");

}else{

  1. updateListElement.setResourceType("Folder");

}

}else{

  1. updateListElement.setResourceType("Link");

}

// keyword property name

IPropertyName keywords_property_name = null;

keywords_property_name = PropertyName.getPN(http://XXXXXXX, "Keywords");

// information property name

IPropertyName information_property_name = null;

information_property_name = PropertyName.getPN("http://XXXXXXX","Information");

// owner property name

IPropertyName owner_property_name = null;

owner_property_name = PropertyName.getPN("http://XXXXXXX", "owner");

// get keywords

IProperty keywords_property = tempResource.getProperty(keywords_property_name);

if(keywords_property!=null){

String keywords_property_value = keywords_property.getStringValue();

String keywords = keywords_property_value.trim();

  1. updateListElement.setKeyWords(keywords);

}

// get information

IProperty information_property = tempResource.getProperty(information_property_name);

if(information_property!=null){

String information_property_value = information_property.getValueAsString();

String information = information_property_value.trim();

  1. updateListElement.setInfromation(information);

}

// get owner

IProperty owner_property = tempResource.getProperty(owner_property_name);

if(owner_property!=null){

String owner_property_value = owner_property.getValueAsString();

String owner = owner_property_value.trim();

  1. updateListElement.setResponsible(owner);

}

// get GUID

IUriMapperService uriMapperService = (IUriMapperService)ResourceFactory.getInstance().getServiceFactory().getService(IUriMapperService.SERVICE_ID);

RID guid = uriMapperService.getGuidRIDFromRID(tempResource.getRID());

  1. updateListElement.setGUID(guid.toString());

// get FileSize

String fileSize = "0";

if(tempResource.getContent().getContentLength() == -1)

{

double d1 = 0.0;

d1 = tempResource.getContent().getInputStream().available();

fileSize = this.getFileSize(d1);

  1. updateListElement.setFileSize(fileSize);

//wdComponentAPI.getMessageManager().reportSuccess("inSide IF:"+fileSize);

} // end fileSize

else

{

fileSize = this.getFileSize(tempResource.getContent().getContentLength());

  1. updateListElement.setFileSize(fileSize);

//wdComponentAPI.getMessageManager().reportSuccess("inSide else:"+fileSize);

}

 

// get MIMEtype

  1. updateListElement.setMIMEType(tempResource.getContent().getContentType());

//wdComponentAPI.getMessageManager().reportSuccess(" tempResource.getContent().getContentType(): "+tempResource.getContent().getContentType());

 

// get FilePath

if(tempResource.getRID().getPath()!=null){

  1. updateListElement.setFilePath(tempResource.getRID().getPath());

//wdComponentAPI.getMessageManager().reportSuccess("tempResource.getRID().getPath():"+tempResource.getRID().getPath());

}

// get CreatedBy

if(tempResource.getCreatedBy()!=null){

IUser createUserName = (IUser)WPUMFactory.getUserFactory().getUser(tempResource.getCreatedBy());

String createuserName = createUserName.getDisplayName();

  1. updateListElement.setCreatedBy(createuserName);

}

// get Created Date

SimpleDateFormat ft = new SimpleDateFormat ("MM/dd/yyyy hh:mm:ss a");

if(tempResource.getCreationDate()!=null){

Date strDate = tempResource.getCreationDate();

String strDate1 = ft.format(strDate);

  1. updateListElement.setCreatedDate(strDate1);

}

// get ModifiedBy

if(tempResource.getLastModifiedBy()!=null){

IUser modifiedUserName = (IUser)WPUMFactory.getUserFactory().getUser(tempResource.getLastModifiedBy());

String modifieduserName = modifiedUserName.getDisplayName();

  1. updateListElement.setModifiedBy(modifieduserName);

}

// get ModifiedDate

if(tempResource.getLastModified()!=null){

Date modifiedDate = tempResource.getLastModified();

String modifiedDate1 = ft.format(modifiedDate);

  1. updateListElement.setModifiedDate(modifiedDate1);

}

/*

* Start get the KM Resource Permitions

*

*/

ISecurityManager sm = tempResource.getRepositoryManager().getSecurityManager(tempResource);

if(sm!=null&& sm instanceof IAclSecurityManager)

{

IAclSecurityManager asm = (IAclSecurityManager)sm;

IResourceAclManager ram = asm.getAclManager();

String kmResPermissions = null;

IResourceAclEntryListIterator aclList = null;

IResourceAclEntry acl = null;

IResourceAcl ra = ram.getAcl(tempResource);

//wdComponentAPI.getMessageManager().reportSuccess("ra:"+ra);

if(ra==null)

{

ra = ram.getInheritedAcl(tempResource);

//wdComponentAPI.getMessageManager().reportSuccess("ra inSide if:"+ra);

aclList = ra.getEntries().iterator();

//wdComponentAPI.getMessageManager().reportSuccess("aclList:"+aclList);

}

if (ra != null)

{

for(aclList = ra.getEntries().iterator(); aclList.hasNext();)

{

acl = aclList.next();

//wdComponentAPI.getMessageManager().reportSuccess("acl.getPrincipal().getType():"+acl.getPrincipal().getType());

if (acl.getPrincipal().getType() == 1) // User Type = 0; Group Type = 1; Role Type = 2

{

if(kmResPermissions == null)

{

kmResPermissions = acl.getPrincipal().getDisplayName() + "["+acl.getPermission().getDescription()+"]";

//wdComponentAPI.getMessageManager().reportSuccess("Group Type = 1(if)kmResPermissions:"+kmResPermissions);

  1. updateListElement.setPermissions(kmResPermissions);

} // end kmResPermissions

else

{

kmResPermissions = acl.getPrincipal().getDisplayName() + "["+acl.getPermission().getDescription()+"]";

//wdComponentAPI.getMessageManager().reportSuccess("Group Type = 1(else) kmResPermissions:"+kmResPermissions);

  1. updateListElement.setPermissions(kmResPermissions);

}

} // end if Group Type = 1

elseif(acl.getPrincipal().getType() == 0) // User Type = 0

{

if(kmResPermissions == null)

{

kmResPermissions = acl.getPrincipal().getDisplayName() + "["+acl.getPermission().getDescription()+"]";

//wdComponentAPI.getMessageManager().reportSuccess("User Type = 0(if)kmResPermissions:"+kmResPermissions);

  1. updateListElement.setPermissions(kmResPermissions);
  2. wdComponentAPI.getMessageManager().reportSuccess("getOwners:"+acl.getPermission().getName());

} // end kmResPermissions

else

{

String kmResMainPer = acl.getPrincipal().getDisplayName() + "["+acl.getPermission().getDescription()+"]";

kmResPermissions = kmResPermissions + ','+kmResMainPer;

  1. updateListElement.setPermissions(kmResPermissions);

}

} // end if User Type = 0

elseif(acl.getPrincipal().getType() == 2)

{

if(kmResPermissions == null)

{

kmResPermissions = acl.getPrincipal().getDisplayName() + "["+acl.getPermission().getDescription()+"]";

//wdComponentAPI.getMessageManager().reportSuccess("Role Type = 2(if)kmResPermissions for User:"+kmResPermissions);

  1. updateListElement.setPermissions(kmResPermissions);

} // end kmResPermissions

else

{

String kmResMainPer = acl.getPrincipal().getDisplayName() + "["+acl.getPermission().getDescription()+"]";

kmResPermissions = kmResPermissions + ','+kmResMainPer;

  1. updateListElement.setPermissions(kmResPermissions);

}

} // end if User Type = 2

}

}

} // end sm

// End get the KM Resource Permitions

// get LinkTarget

IWDRequest req=WDProtocolAdapter.getProtocolAdapter().getRequestObject();

String serverName = req.getServerName();

int serverPort = req.getServerPort();

String protocalName = "http://";

String portalDevURL = ".auto.wan.com:";

String targetLink = generateUrlForResource(tempResource);

String finalTargetLink = protocalName+serverName+portalDevURL+serverPort+targetLink;

  1. updateListElement.setLinkTarget(finalTargetLink);
  2. wdContext.nodeUpdateList().addElement(updateListElement);

//i++;

} // end if (tempResource.isCollection() || !tempResource.isCollection())

 

 

addEntriesToUpdateList(tempResource.toString());

 

}// end While

} // end resource.isCollection()

}catch(Exception e){

  1. wdComponentAPI.getMessageManager().reportException("Exception:"+e.getMessage(),true);

}

}

// This methos is used In "onActionUpdate" method

privatevoid checkManditory() {

// Check for a value in the Required Field REPLACE

IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();

if (wdContext.currentUpdateElement().getReplace().toString().length()== 0) {

  1. msgMgr.reportContextAttributeMessage(
  2. wdContext.currentUpdateElement(),
  3. wdContext.nodeUpdate().getNodeInfo().getAttribute(wdContext.currentUpdateElement().REPLACE),IMessageCO_kmFolderTree.REQUIRED__FIELD, null, true);

}

if (wdContext.currentUpdateElement().getFind().toString().length() == 0) {

  1. msgMgr.reportContextAttributeMessage(
  2. wdContext.currentUpdateElement(),
  3. wdContext.nodeUpdate().getNodeInfo().getAttribute(wdContext.currentUpdateElement().FIND),IMessageCO_kmFolderTree.REQUIRED__FIELD, null, true);

}

}

private String getFileSize(double fileSize) {

InputStream stream = null;

DecimalFormat myFormatter = new DecimalFormat("###.##");

String unit = "";

try {

if (fileSize < 1024) {

unit = " Bytes";

}

elseif (fileSize < 1048576) {

fileSize = fileSize / 1024;

unit = " KB";

}elseif (fileSize < 1073741824) {

fileSize = fileSize / 1024 / 1024;

unit = " MB";

}

}

finally {

if (stream != null) {

try {

  1. stream.close();

} catch (IOException e) {

  1. wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage(), true);

}

}

}

return myFormatter.format(fileSize) + unit;

}

String Admin_Service_User = "cmadmin_service";

int totalResList;

BufferedWriter logFile = null;

//@@end

}

 

 

 

 

Regards

Vijay K Kalluri


Viewing all articles
Browse latest Browse all 1288

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>