Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
I was recently looking for information about how to get information about portal repositories activity. This information should be easy to understand because potential users won't have very strong technical skills.

The solution to get an easy report about document usage was expose by Detlev Beutner in SDN forums and it's based on developing a repository service which counts documents hits.

These are the steps to get this functionality:

  • Creating a custom property which registers documents hits in those repositories you want to control.
  • Developing a repository service which reponds when a document is read and increment the new property.
  • Activating the new service in repositories.

Step 1: Creating a custom property: hitscount

Creating a new property is easy in Enterprise Portal.
Go to
System Administration/System configuration/Knowledge Management/Configuration/Content Management/Global Services/Property Metadata/Properties
and create a new property with the following attributes:

Description = Hit Counter
Unique ID = hitscount
Property ID = hitscount
Namespace alias = default
Type = Integer
Group = default
Mandatory = deactivated
Multi-Valued = deactivated
Read Only = activated
Maintainable = activated
Indexable = activated
Default Value = 0
Allowed Values (csv) = empty
Key for Label = hitscount
Meta Data Extension = Not set
Folder Validity Patterns (csv) = empty
Document Validity Patterns (csv) = repository list
Resource Types (csv) = empty
Mime Types (csv) = empty
Default Sorting = Ascending
Label icon = empty
Hidden = deactivated
Dependencies = deactivated
Additional Metadata (csv) = empty
Property Renderer = integer
Virtual = deactivated
Composed of = none selected
Comparator Class = empty

Now, every documents in the repository list will have this new property (upload a new document and look in its details page, inside Miscellaneous tab!).

Step 2: Developing a repository service

Once we have created this new property we need a repository service which control it increasing his value in each document access.

To develop it we have used SAP Netweaver Developer Studio 2.0.12 with Repository Framework 7.1.5.
Substeps are:

  • Create a new Portal Application Project
  • Create a new Repository Service using whe wizard

Now, you must have three classes in your project structure: IRFServiceWrapper, RFServiceWrapper and one class with the name you gave in creation, in our case: SampleService.
  • Fill theKEY attribute inside IRFServiceWrapper. Tipically with a string like "com.mycompany.SampleService".

Copy and paste the following code into SampleService class. You can take a quick look at this code to know what is it doing. We are subscribing to GET_TEMPLATE event.

package com.mycompany;

import java.util.Collection;
import java.util.Iterator;

import com.sapportals.wcm.WcmException;
import com.sapportals.wcm.crt.component.IReconfigurable;
import com.sapportals.wcm.crt.component.StartupException;
import com.sapportals.wcm.crt.configuration.ConfigurationException;
import com.sapportals.wcm.crt.configuration.IConfiguration;
import com.sapportals.wcm.repository.IProperty;
import com.sapportals.wcm.repository.IResource;
import com.sapportals.wcm.repository.Property;
import com.sapportals.wcm.repository.PropertyName;
import com.sapportals.wcm.repository.ResourceException;
import com.sapportals.wcm.repository.manager.IRepositoryManager;
import com.sapportals.wcm.repository.manager.IResourceEvent;
import com.sapportals.wcm.repository.manager.IResourceEventReceiver;
import com.sapportals.wcm.repository.manager.ResourceEvent;
import com.sapportals.wcm.repository.service.AbstractRepositoryService;
import com.sapportals.wcm.repository.service.ServiceNotAvailableException;
import com.sapportals.wcm.util.events.IEvent;

public class SampleService extends AbstractRepositoryService implements IResourceEventReceiver, IReconfigurable {

private static final String TYPE = "com.mycompany.kmservice.SampleService";
private Collection repositoryManagers;

public SampleService() {
  super();
}

public String getServiceType() {
  return SampleService.TYPE;
}

protected void startUpImpl(Collection repositoryManagers) throws ConfigurationException, StartupException {

  this.repositoryManagers = repositoryManagers;
  Iterator it = repositoryManagers.iterator();
  while (it.hasNext()){
    try {
      addRepositoryAssignment((IRepositoryManager) it.next());
    } catch (ServiceNotAvailableException e) {
      e.printStackTrace();
    }
  }
}

protected void shutDownImpl() {
  Iterator it = repositoryManagers.iterator();
  while (it.hasNext()){
    try {
      removeRepositoryAssignment((IRepositoryManager) it.next());
    } catch (WcmException e) {
      e.printStackTrace();
    }
  }
}

protected void addRepositoryAssignment(IRepositoryManager mgr) throws ServiceNotAvailableException {
  try {
    mgr.getEventBroker().register(this, ResourceEvent.GET_TEMPLATE);
  } catch (WcmException e) {
    e.printStackTrace();
  }
}

protected void removeRepositoryAssignment(IRepositoryManager mgr) throws WcmException {
  mgr.getEventBroker().unregister(this, ResourceEvent.GET_TEMPLATE);
}

public void received(IEvent event) {
  IResourceEvent myEvent = (IResourceEvent) event;
  try {

    IResource res = myEvent.getResource();
    
    PropertyName propertyNameHitCount = new PropertyName("http://sapportals.com/xmlns/cm","hitscount");
    Property propHitCount = new Property(propertyNameHitCount,new Integer(0));

    // We increase hitscount property value
    if (res.getProperty(propertyNameHitCount)!=null) {
      IProperty oldHitCount = res.getProperty(propertyNameHitCount);
      String sOldHitCount = oldHitCount.getValueAsString();
      int iOldHitCount = Integer.parseInt(sOldHitCount);
      iOldHitCount++;
      propHitCount = new Property(propertyNameHitCount,new Integer(iOldHitCount));
      res.setProperty(propHitCount);
    }

  } catch (ResourceException e) {
    e.printStackTrace();
  }
}

public void reconfigure(IConfiguration arg0) throws ConfigurationException {
}
}


Step 3: Activating the new service

The new service must be activated in those repositories that you want to control.

To do this you can go to
System Administration/System configuration/Knowledge Management/Configuration/Content Management/Repository Managers/CM Repository
and check the repositories to control.

Is important to restart servlet engine.

In Summary

This is a easy solution to know how many users have read one document in knowledge management.


14 Comments