Get the File/Folder/Link information form KM repository by using Webdynpro JAVA
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
- 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
Output Structure by using Webdynpro JAVA
2. Context:-
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:-
Table Structure in Webdynpro JAVA Application
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
public class V_kmFolderTreeView
{
/**
* Logging location.
*/
private static final com.sap.tc.logging.Location logger =
- com.sap.tc.logging.Location.getLocation(V_kmFolderTreeView.class);
static
{
//@@begin id
String id = “$Id$”;
//@@end
- com.sap.tc.logging.Location.getLocation(“ID.com.sap.tc.webdynpro”).infoT(id);
}
/**
* Private access to the generated Web Dynpro counterpart
* for this controller class. </p>
*
* Use <code>wdThis</code> to gain typed access to the context,
* to trigger navigation via outbound plugs, to get and enable/disable
* actions, fire declared events, and access used controllers and/or
* component usages.
*
* @see com.corp.iview.i_v_kmfoldertreeview.com.wdp.IPrivateV_kmFolderTreeView for more details
*/
private final IPrivateV_kmFolderTreeView wdThis;
/**
* Root node of this controller’s context. </p>
*
* Provides typed access not only to the elements of the root node
* but also to all nodes in the context (methods node<i>XYZ</i>())
* and their currently selected element (methods current<i>XYZ</i>Element()).
* It also facilitates the creation of new elements for all nodes
* (methods create<i>XYZ</i>Element()). </p>
*
* @see com.corp.iview.i_v_kmfoldertreeview.com.wdp.IPrivateV_kmFolderTreeView.IContextNode for more details.
*/
private final IPrivateV_kmFolderTreeView.IContextNode wdContext;
/**
* A shortcut for <code>wdThis.wdGetAPI()</code>. </p>
*
* Represents the generic API of the generic Web Dynpro counterpart
* for this controller. </p>
*/
private final com.sap.tc.webdynpro.progmodel.api.IWDViewController wdControllerAPI;
/**
* A shortcut for <code>wdThis.wdGetAPI().getComponent()</code>. </p>
*
* Represents the generic API of the Web Dynpro component this controller
* belongs to. Can be used to access the message manager, the window manager,
* to add/remove event handlers and so on. </p>
*/
private final com.sap.tc.webdynpro.progmodel.api.IWDComponent wdComponentAPI;
public V_kmFolderTreeView(IPrivateV_kmFolderTreeView wdThis)
{
- this.wdThis = wdThis;
- this.wdContext = wdThis.wdGetContext();
- this.wdControllerAPI = wdThis.wdGetAPI();
- this.wdComponentAPI = wdThis.wdGetAPI().getComponent();
}
//@@begin javadoc:wdDoInit()
/** Hook method called to initialize controller. */
//@@end
public void wdDoInit()
{
//@@begin wdDoInit()
initializeRepositoryTree();
//@@end
}
//@@begin javadoc:wdDoExit()
/** Hook method called to clean up controller. */
//@@end
public void wdDoExit()
{
//@@begin wdDoExit()
//@@end
}
//@@begin javadoc:wdDoModifyView
/**
* Hook method called to modify a view just before rendering.
* This method conceptually belongs to the view itself, not to the
* controller (cf. MVC pattern).
* It is made static to discourage a way of programming that
* routinely stores references to UI elements in instance fields
* for access by the view controller’s event handlers, and so on.
* The Web Dynpro programming model recommends that UI elements can
* only be accessed by code executed within the call to this hook method.
*
* @param wdThis Generated private interface of the view’s controller, as
* provided by Web Dynpro. Provides access to the view controller’s
* outgoing controller usages, etc.
* @param wdContext Generated interface of the view’s context, as provided
* by Web Dynpro. Provides access to the view’s data.
* @param view The view’s generic API, as provided by Web Dynpro.
* Provides access to UI elements.
* @param firstTime Indicates whether the hook is called for the first time
* during the lifetime of the view.
*/
//@@end
public static void 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”);
- treeNode.mappingOfOnAction().addSourceMapping(“path”,“elementSelection”);
- treeNode.mappingOfOnLoadChildren().addSourceMapping(“path”, “element”);
}
//@@end
}
//@@begin javadoc:get_child_resources()
/** Declared method. */
//@@end
public void get_child_resources( java.lang.String tempResource )
{
//@@begin get_child_resources()
addEntriesToUpdateList(tempResource);
//@@end
}
//@@begin javadoc:onActionshowHideTree(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionshowHideTree(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionshowHideTree(ServerEvent)
if (wdContext.currentUpdateElement().getTreeShow() == WDVisibility.VISIBLE) {
- wdContext.currentUpdateElement().setCollapseIcon(“~sapicons/s_b_pagr.gif”);
- wdContext.currentUpdateElement().setTreeShow(WDVisibility.NONE);
} else {
- wdContext.currentUpdateElement().setCollapseIcon(“~sapicons/s_b_pagl.gif”);
- wdContext.currentUpdateElement().setTreeShow(WDVisibility.VISIBLE);
}
//@@end
}
//@@begin javadoc:onActionNodeSelection(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionNodeSelection(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.corp.iview.i_v_kmfoldertreeview.com.wdp.IPrivateV_kmFolderTreeView.IFolderContentElement elementSelection )
{
//@@begin onActionNodeSelection(ServerEvent)
- wdContext.currentUpdateElement().setInputEnabled(true);
- wdContext.currentUpdateElement().setFolderPath(elementSelection.getPath());
// wdComponentAPI.getMessageManager().reportSuccess(“Path:-“+elementSelection.getPath());
- wdContext.nodeUpdateList().invalidate();
- wdContext.nodeUpdateList().clearSelection();
//@@end
}
//@@begin javadoc:onActionLoadChildren(ServerEvent)
/** Declared validating event handler. */
//@@end
public void 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)
/** Declared validating event handler. */
//@@end
public void onActionfindOnly(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionfindOnly(ServerEvent)
// For Find Only (no Replace) we only need to confirm
- wdContext.nodeUpdateList().invalidate();
// wdComponentAPI.getMessageManager().reportSuccess(“Path:”+wdContext.currentUpdateElement().getFolderPath());
addEntriesToUpdateList(wdContext.currentUpdateElement().getFolderPath());
- wdComponentAPI.getMessageManager().reportSuccess(“Search Complete”);
//wdContext.nodeUpdateList().setLeadSelection(-1);
//@@end
}
//@@begin javadoc:onActionexportExcel(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionexportExcel(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionexportExcel(ServerEvent)
// wdThis.wdGetCO_kmFolderTreeController().downloadData(wdContext.nodeUpdateList());
- wdThis.wdGetCO_kmFolderTreeController().Export_to_excel(getKMResourceColumnInfos(),wdContext.nodeUpdateList());
//@@end
}
//@@begin javadoc:onActiongetChild_KM_ResourceFiles(ServerEvent)
/** Declared validating event handler. */
//@@end
public void 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());
- wdContext.currentUpdateListElement().setCheckKMResource(true);
}else
{
- wdComponentAPI.getMessageManager().reportWarning(“KM Resource Files already avaliable in Table”);
}
- wdContext.nodeUpdateList().setLeadSelection(-1);
//@@end
}
//@@begin javadoc:onActionReadFile(ServerEvent)
/** Declared validating event handler. */
//@@end
public void 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
private void 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);
- folderContentNode.addElement(folderContentElement);
- parent.setIsExpand(true);
hasChildren = true;
}
}if (!hasChildren) {
- parent.setHasChildren(false);
}
} catch (Exception e) {
- e.printStackTrace();
}
}
private void addFolderToContextNode(IFolderContentElement element, IResource tempResource, RID pathRID) throws Exception {
// Entry is a Folder
- element.setHasChildren(true);
- element.setIconSource(“~sapicons/s_clofol.gif”);
// Use the Name if the DisplayName is Blank
if (tempResource.getDisplayName() == “”) {
- element.setText(tempResource.getName());
} else {
- 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 =
- RID.getRID(pathRID.toString() + tempResource.getName());
} else {
directoryToOpenRID = RID.getRID(pathRID.toString() + “/” + tempResource.getName());
}
// set the selected directory as the new path
- element.setPath(directoryToOpenRID.toString());
- element.setIsExpand(false);
}
private IResourceContext buildResourceContext() throws Exception {
// create an user object from the current user
IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
- 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;
}
private void 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
- resourceList.sort(rRPC); }
private void initializeRepositoryTree() {
IFolderContentNode rootFolderContentNode = wdContext.nodeFolderContent();
IFolderContentElement rootFolderContentElement;
rootFolderContentElement = rootFolderContentNode.createFolderContentElement();
- rootFolderContentElement.setPath(“/documents/Another FolderName/Folder View”);
- rootFolderContentElement.setIsExpand(true);
- rootFolderContentElement.setText(“/Folder View”);
- rootFolderContentElement.setHasChildren(true);
- rootFolderContentElement.setIconSource(“~sapicons/s_clofol.gif”);
- 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();
}
private void 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
{
- 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();
- updateListElement.setFilePath(path);
//get ResourceName
if (tempResource.getDisplayName() == “” && (tempResource.getDisplayName()!=null || tempResource.getDisplayName()==null))
{
- updateListElement.setFileName(tempResource.getName());
}else
{
- updateListElement.setFileName(tempResource.getDisplayName());
}
// get Discription
if(tempResource.getDescription()!=null || tempResource.getDescription()==null){
- updateListElement.setFileDiscription(tempResource.getDescription());
}
// get ResourceType
if(tempResource.getTargetURL()==null){
if(tempResource.getContent().getContentType() != null && tempResource.getContent().getContentType() != “”){
- updateListElement.setResourceType(“File”);
}else{
- updateListElement.setResourceType(“Folder”);
}
}else{
- 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();
- 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();
- 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();
- updateListElement.setResponsible(owner);
}
// get GUID
IUriMapperService uriMapperService = (IUriMapperService)ResourceFactory.getInstance().getServiceFactory().getService(IUriMapperService.SERVICE_ID);
RID guid = uriMapperService.getGuidRIDFromRID(tempResource.getRID());
- 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);
- updateListElement.setFileSize(fileSize);
//wdComponentAPI.getMessageManager().reportSuccess(“inSide IF:”+fileSize);
} // end fileSize
else
{
fileSize = this.getFileSize(tempResource.getContent().getContentLength());
- updateListElement.setFileSize(fileSize);
//wdComponentAPI.getMessageManager().reportSuccess(“inSide else:”+fileSize);
}
// get MIMEtype
- updateListElement.setMIMEType(tempResource.getContent().getContentType());
//wdComponentAPI.getMessageManager().reportSuccess(” tempResource.getContent().getContentType(): “+tempResource.getContent().getContentType());
// get FilePath
if(tempResource.getRID().getPath()!=null){
- 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();
- 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);
- updateListElement.setCreatedDate(strDate1);
}
// get ModifiedBy
if(tempResource.getLastModifiedBy()!=null){
IUser modifiedUserName = (IUser)WPUMFactory.getUserFactory().getUser(tempResource.getLastModifiedBy());
String modifieduserName = modifiedUserName.getDisplayName();
- updateListElement.setModifiedBy(modifieduserName);
}
// get ModifiedDate
if(tempResource.getLastModified()!=null){
Date modifiedDate = tempResource.getLastModified();
String modifiedDate1 = ft.format(modifiedDate);
- 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);
- updateListElement.setPermissions(kmResPermissions);
} // end kmResPermissions
else
{
kmResPermissions = acl.getPrincipal().getDisplayName() + “[“+acl.getPermission().getDescription()+“]”;
//wdComponentAPI.getMessageManager().reportSuccess(“Group Type = 1(else) kmResPermissions:”+kmResPermissions);
- updateListElement.setPermissions(kmResPermissions);
}
} // end if Group Type = 1
else if(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);
- updateListElement.setPermissions(kmResPermissions);
- wdComponentAPI.getMessageManager().reportSuccess(“getOwners:”+acl.getPermission().getName());
} // end kmResPermissions
else
{
String kmResMainPer = acl.getPrincipal().getDisplayName() + “[“+acl.getPermission().getDescription()+“]”;
kmResPermissions = kmResPermissions + ‘,’+kmResMainPer;
- updateListElement.setPermissions(kmResPermissions);
}
} // end if User Type = 0
else if(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);
- updateListElement.setPermissions(kmResPermissions);
} // end kmResPermissions
else
{
String kmResMainPer = acl.getPrincipal().getDisplayName() + “[“+acl.getPermission().getDescription()+“]”;
kmResPermissions = kmResPermissions + ‘,’+kmResMainPer;
- 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;
- updateListElement.setLinkTarget(finalTargetLink);
- wdContext.nodeUpdateList().addElement(updateListElement);
//i++;
} // end if (tempResource.isCollection() || !tempResource.isCollection())
addEntriesToUpdateList(tempResource.toString());
}// end While
} // end resource.isCollection()
}catch(Exception e){
- wdComponentAPI.getMessageManager().reportException(“Exception:”+e.getMessage(),true);
}
}
// This methos is used In “onActionUpdate” method
private void checkManditory() {
// Check for a value in the Required Field REPLACE
IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();
if (wdContext.currentUpdateElement().getReplace().toString().length()== 0) {
- msgMgr.reportContextAttributeMessage(
- wdContext.currentUpdateElement(),
- wdContext.nodeUpdate().getNodeInfo().getAttribute(wdContext.currentUpdateElement().REPLACE),IMessageCO_kmFolderTree.REQUIRED__FIELD, null, true);
}
if (wdContext.currentUpdateElement().getFind().toString().length() == 0) {
- msgMgr.reportContextAttributeMessage(
- wdContext.currentUpdateElement(),
- 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”;
}
else if (fileSize < 1048576) {
fileSize = fileSize / 1024;
unit = ” KB”;
}else if (fileSize < 1073741824) {
fileSize = fileSize / 1024 / 1024;
unit = ” MB”;
}
}
finally {
if (stream != null) {
try {
- stream.close();
} catch (IOException e) {
- 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
Nice Blog... Very clear and informative...
Its very nice and useful blog