Dear all,
I created two repository services: 1st to set document's lifetime of 1 day, 2nd to delete document at end of validity event. Both services are developed in NWDS 7.0.11 and deployed on SAP EP NW 7.01 sp5 and they are running. But, I see nothing happened when testing.
KM Content structure
/root
/folder
/subfolders
document1
document2 ......
Thanks a lot for advising.
these are the 2 services code:
1/ To set lifetime:
packagecom.chorus;
importjava.text.ParseException;
importjava.text.SimpleDateFormat;
importjava.util.Calendar;
importjava.util.Collection;
importjava.util.Date;
importcom.sap.engine.lib.xml.signature.elements.Object;
importcom.sap.netweaver.bc.rf.util.event.IEventBroker;
importcom.sapportals.portal.prt.component.IPortalComponentRequest;
importcom.sapportals.portal.prt.logger.ILogger;
importcom.sapportals.portal.prt.runtime.PortalRuntime;
importcom.sapportals.portal.security.usermanagement.UserManagementException;
importcom.sapportals.wcm.IWcmConst;
importcom.sapportals.wcm.WcmException;
importcom.sapportals.wcm.crt.component.IReconfigurable;
importcom.sapportals.wcm.crt.component.StartupException;
importcom.sapportals.wcm.crt.configuration.ConfigurationException;
importcom.sapportals.wcm.crt.configuration.IConfiguration;
importcom.sapportals.wcm.repository.ICollection;
importcom.sapportals.wcm.repository.IResource;
importcom.sapportals.wcm.repository.IResourceContext;
importcom.sapportals.wcm.repository.IResourceFactory;
importcom.sapportals.wcm.repository.IResourceList;
importcom.sapportals.wcm.repository.IResourceListIterator;
importcom.sapportals.wcm.repository.ResourceContext;
importcom.sapportals.wcm.repository.ResourceException;
importcom.sapportals.wcm.repository.ResourceFactory;
importcom.sapportals.wcm.repository.manager.IRepositoryManager;
importcom.sapportals.wcm.repository.manager.IResourceEvent;
importcom.sapportals.wcm.repository.manager.IResourceEventReceiver;
importcom.sapportals.wcm.repository.manager.ResourceEvent;
importcom.sapportals.wcm.repository.service.AbstractRepositoryService;
importcom.sapportals.wcm.repository.service.IRepositoryService;
importcom.sapportals.wcm.repository.service.IRepositoryServiceFactory;
importcom.sapportals.wcm.repository.service.ServiceNotAvailableException;
importcom
.sapportals
.wcm
.repository
.service
.timebasedpublish
.ITimebasedPublishServiceManager;
importcom
.sapportals
.wcm
.repository
.service
.timebasedpublish
.TimebasedPublishConstants;
importcom.sapportals.wcm.util.events.IEvent;
importcom.sapportals.wcm.util.uri.RID;
importcom.sapportals.wcm.util.usermanagement.WPUMFactory;
// implements IMyNewRepositoryService interface
/*
Note: IReconfigurable and IResourceEventReceiver interfaces are optional
*/
publicclassRepServiceAEK
extendsAbstractRepositoryService
implementsIReconfigurable,IResourceEventReceiver{
privatestaticfinalStringTYPE="RepServiceAEK";
privateRIDrid=RID.getRID("/BIuserhome/");
privateCollectionrepositoryManagers;
IPortalComponentRequestrequest=null;
publicRepServiceAEK(){
super();
// Do not add code here. Add it to startUpImpl() instead
}
publicStringgetServiceType(){
returnRepServiceAEK.TYPE;
}
protectedvoidstartUpImpl(CollectionrepositoryManagers)
throwsConfigurationException,StartupException{
// implement this method as follows:
// - Verify configuration data
// - Get references to other needed (global) services
// - Check whether other repository services (this service depends on) are also assigned to the repository managers
// - Usually the service registers itself for certain events at all repository managers
//
try{
com.sapportals.portal.security.usermanagement.IUseruser=
WPUMFactory.getUserFactory().getEP5User(request.getUser());
IResourceFactoryresourceFactory=ResourceFactory.getInstance();
IResourceContextcontext=newResourceContext(user);
// home folder
IResourceresource=resourceFactory.getResource(rid,context);
if(resource.isCollection()){
ICollectionparent=(ICollection)resource;
// user's folder
IResourceListchildren=parent.getChildren();
if(children.size()>0){
IResourceListIteratoriter=children.listIterator();
while(iter.hasNext()){
IResourceelement=(IResource)iter.next();
addRepositoryAssignment((IRepositoryManager)element);
}
}
}
}catch(ResourceExceptione){
// TODO Auto-generated catch block
e.printStackTrace();
}catch(UserManagementExceptione1){
// TODO Auto-generated catch block
e1.printStackTrace();
}catch(NullPointerExceptione2){
// TODO: handle exception
e2.getMessage();
}catch(SecurityExceptione3){
// TODO Auto-generated catch block
e3.printStackTrace();
}
}
protectedvoidshutDownImpl(){
try{
com.sapportals.portal.security.usermanagement.IUseruser=
WPUMFactory.getUserFactory().getEP5User(request.getUser());
IResourceFactoryresourceFactory=ResourceFactory.getInstance();
IResourceContextcontext=newResourceContext(user);
//home folder
IResourceresource=resourceFactory.getResource(rid,context);
if(resource.isCollection()){
ICollectionparent=(ICollection)resource;
// user's folder
IResourceListchildren=parent.getChildren();
if(children.size()>0){
IResourceListIteratoriter=children.listIterator();
while(iter.hasNext()){
IResourceelement=(IResource)iter.next();
addRepositoryAssignment((IRepositoryManager)element);
}
}
}
}catch(ResourceExceptione){
// TODO Auto-generated catch block
e.printStackTrace();
}catch(UserManagementExceptione1){
// TODO Auto-generated catch block
e1.printStackTrace();
}catch(WcmExceptione2){
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
protectedvoidaddRepositoryAssignment(IRepositoryManagermgr)
throwsServiceNotAvailableException{
// Implement this method: Usually the service registers itself for certain events at the repository manager.
try{
mgr.getEventBroker().register(
this,
ResourceEvent.CREATE_CHILD_TEMPLATE);
}catch(WcmExceptione){
// TODO: handle exception
e.printStackTrace();
}
}
/**
*@paramevent
*@paramobject
*/
privatevoidResourceEvent(ResourceEventevent,Objectobject){
// TODO Auto-generated method stub
}
protectedvoidremoveRepositoryAssignment(IRepositoryManagermgr)
throwsWcmException{
// Implement this method: Usually the service must unregister itself as an event handler.
try{
mgr.getEventBroker().unregister(
this,
ResourceEvent.CREATE_CHILD_TEMPLATE);
}catch(WcmExceptione){
// TODO: handle exception
e.printStackTrace();
}
}
publicvoidreconfigure(IConfigurationconfig)
throwsConfigurationException{
this.stateHandler.preReconfigure();
// check the new configuration data
/*
try {
}
catch (ConfigurationException ex) {
this.stateHandler.postReconfigure(ex);
throw ex;
}
*/
this.config=config;
this.stateHandler.postReconfigure();
}
publicvoidreceived(IEventevent){
ILoggerlogger=PortalRuntime.getLogger();
logger.severe(TYPE,"Start RepServiceAEK");
if(eventinstanceofIResourceEvent){
IResourceEventresourceEvent=(IResourceEvent)event;
if(resourceEvent.getResource()==ResourceEvent.CREATE_CHILD_TEMPLATE){//getType()
try{
IResourceresource=
(IResource)resourceEvent.getResource();//getParameter()
IRepositoryServiceFactoryrepServiceFactory=
ResourceFactory.getInstance().getServiceFactory();
IRepositoryServicerepService=
repServiceFactory.getRepositoryService(
resource,
IWcmConst.TIMEBASED_PUBLISH_SERVICE);
ITimebasedPublishServiceManagertbpService=
(ITimebasedPublishServiceManager)repService;
resource.deleteProperty(
TimebasedPublishConstants.getValidFromPropName());
resource.deleteProperty(
TimebasedPublishConstants.getValidToPropName());
SimpleDateFormatsdf=
newSimpleDateFormat("mm/dd/yyyy");
// start date
Calendarcal=Calendar.getInstance();
Datedate=newDate();
cal.setTime(date);
Stringcurrdate=sdf.format(date);
// end date
cal.add(Calendar.DATE,1);
Datedate1=cal.getTime();
Stringenddate=sdf.format(date1);
DatevalidFrom=sdf.parse(currdate);
DatevalidTo=sdf.parse(enddate);
tbpService.saveValidDate(resource,validFrom);
tbpService.saveInvalidDate(resource,validTo);
}catch(ResourceExceptione){
// TODO Auto-generated catch block
e.printStackTrace();
}catch(ParseExceptione){
// TODO Auto-generated catch block
e.printStackTrace();
}catch(WcmExceptione){
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
logger.severe(TYPE,"End RepServiceAEK");
}
}
2/ to delete document
packagecom.chorus;
importjava.util.Collection;
importjava.util.Date;
importcom.sapportals.portal.prt.component.IPortalComponentRequest;
importcom.sapportals.portal.prt.logger.ILogger;
importcom.sapportals.portal.prt.runtime.PortalRuntime;
importcom.sapportals.portal.security.usermanagement.UserManagementException;
importcom.sapportals.wcm.IWcmConst;
importcom.sapportals.wcm.WcmException;
importcom.sapportals.wcm.crt.component.IReconfigurable;
importcom.sapportals.wcm.crt.component.StartupException;
importcom.sapportals.wcm.crt.configuration.ConfigurationException;
importcom.sapportals.wcm.crt.configuration.IConfiguration;
importcom.sapportals.wcm.repository.ICollection;
importcom.sapportals.wcm.repository.IResource;
importcom.sapportals.wcm.repository.IResourceContext;
importcom.sapportals.wcm.repository.IResourceFactory;
importcom.sapportals.wcm.repository.IResourceList;
importcom.sapportals.wcm.repository.IResourceListIterator;
importcom.sapportals.wcm.repository.ResourceContext;
importcom.sapportals.wcm.repository.ResourceException;
importcom.sapportals.wcm.repository.ResourceFactory;
importcom.sapportals.wcm.repository.manager.IRepositoryManager;
importcom.sapportals.wcm.repository.manager.IResourceEvent;
importcom.sapportals.wcm.repository.manager.IResourceEventReceiver;
importcom.sapportals.wcm.repository.service.AbstractRepositoryService;
importcom.sapportals.wcm.repository.service.IRepositoryService;
importcom.sapportals.wcm.repository.service.IRepositoryServiceFactory;
importcom.sapportals.wcm.repository.service.ServiceNotAvailableException;
importcom
.sapportals
.wcm
.repository
.service
.timebasedpublish
.ITimebasedPublishEvent;
importcom
.sapportals
.wcm
.repository
.service
.timebasedpublish
.ITimebasedPublishServiceManager;
importcom
.sapportals
.wcm
.repository
.service
.timebasedpublish
.wcm
.TimebasedPublishEvent;
importcom.sapportals.wcm.util.events.IEvent;
importcom.sapportals.wcm.util.uri.RID;
importcom.sapportals.wcm.util.usermanagement.WPUMFactory;
// implements IMyNewRepositoryService interface
/*
Note: IReconfigurable and IResourceEventReceiver interfaces are optional
*/
publicclassRepServiceAEKStop
extendsAbstractRepositoryService
implementsIReconfigurable,IResourceEventReceiver{
privatestaticfinalStringTYPE="RepServiceAEKStop";
privateRIDrid=RID.getRID("/BIuserhome/");
privateCollectionrepositoryManagers;
IPortalComponentRequestrequest=null;
publicRepServiceAEKStop(){
super();
// Do not add code here. Add it to startUpImpl() instead
}
publicStringgetServiceType(){
returnRepServiceAEKStop.TYPE;
}
protectedvoidstartUpImpl(CollectionrepositoryManagers)
throwsConfigurationException,StartupException{
// implement this method as follows:
// - Verify configuration data
// - Get references to other needed (global) services
// - Check whether other repository services (this service depends on) are also assigned to the repository managers
// - Usually the service registers itself for certain events at all repository managers
//
try{
com.sapportals.portal.security.usermanagement.IUseruser=
WPUMFactory.getUserFactory().getEP5User(request.getUser());
IResourceFactoryresourceFactory=ResourceFactory.getInstance();
IResourceContextcontext=newResourceContext(user);
// home folder
IResourceresource=resourceFactory.getResource(rid,context);
if(resource.isCollection()){
ICollectionparent=(ICollection)resource;
// user's folder
IResourceListchildren=parent.getChildren();
if(children.size()>0){
IResourceListIteratoriter=children.listIterator();
while(iter.hasNext()){
IResourceelement=(IResource)iter.next();
addRepositoryAssignment((IRepositoryManager)element);
}
}
}
}catch(ResourceExceptione){
// TODO Auto-generated catch block
e.printStackTrace();
}catch(UserManagementExceptione1){
// TODO Auto-generated catch block
e1.printStackTrace();
}catch(NullPointerExceptione2){
// TODO: handle exception
e2.getMessage();
}catch(SecurityExceptione3){
// TODO Auto-generated catch block
e3.printStackTrace();
}
}
protectedvoidshutDownImpl(){
try{
com.sapportals.portal.security.usermanagement.IUseruser=
WPUMFactory.getUserFactory().getEP5User(request.getUser());
IResourceFactoryresourceFactory=ResourceFactory.getInstance();
IResourceContextcontext=newResourceContext(user);
// home folder
IResourceresource=resourceFactory.getResource(rid,context);
if(resource.isCollection()){
ICollectionparent=(ICollection)resource;
// user's folder
IResourceListchildren=parent.getChildren();
if(children.size()>0){
IResourceListIteratoriter=children.listIterator();
while(iter.hasNext()){
IResourceelement=(IResource)iter.next();
addRepositoryAssignment((IRepositoryManager)element);
}
}
}
}catch(ResourceExceptione){
// TODO Auto-generated catch block
e.printStackTrace();
}catch(UserManagementExceptione1){
// TODO Auto-generated catch block
e1.printStackTrace();
}catch(WcmExceptione2){
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
protectedvoidaddRepositoryAssignment(IRepositoryManagermgr)
throwsServiceNotAvailableException{
// Implement this method: Usually the service registers itself for certain events at the repository manager.
try{
mgr.getEventBroker().register(
this,
TimebasedPublishEvent.EVENT_TYPE_STOP_TEMPLATE);
}catch(WcmExceptione){
// TODO: handle exception
e.printStackTrace();
}
}
protectedvoidremoveRepositoryAssignment(IRepositoryManagermgr)
throwsWcmException{
// Implement this method: Usually the service must unregister itself as an event handler.
try{
mgr.getEventBroker().unregister(
this,
TimebasedPublishEvent.EVENT_TYPE_STOP_TEMPLATE);
}catch(WcmExceptione){
// TODO: handle exception
e.printStackTrace();
}
}
publicvoidreconfigure(IConfigurationconfig)
throwsConfigurationException{
this.stateHandler.preReconfigure();
// check the new configuration data
/*
try {
}
catch (ConfigurationException ex) {
this.stateHandler.postReconfigure(ex);
throw ex;
}*/
this.config=config;
this.stateHandler.postReconfigure();
}
publicvoidreceived(IEventevent){
ILoggerlogger=PortalRuntime.getLogger();
logger.severe(TYPE,"Start RepServiceAEKStop");
if(eventinstanceofIResourceEvent){
IResourceEventresourceEvent=(IResourceEvent)event;
if(resourceEvent.getType()//getType()
==ITimebasedPublishEvent.EVENT_TYPE_STOP){
try{
IRepositoryServiceFactoryrepServiceFactory;
IResourceresource=
(IResource)resourceEvent.getResource();//getParameter()
repServiceFactory=
ResourceFactory.getInstance().getServiceFactory();
IRepositoryServicerepService=
repServiceFactory.getRepositoryService(
resource,
IWcmConst.TIMEBASED_PUBLISH_SERVICE);
ITimebasedPublishServiceManagertbpService=
(ITimebasedPublishServiceManager)repService;
Datecurrdate=newDate();
DatevalidTo=newDate();
validTo=tbpService.readInvalidDate(resource);
if(currdate.getTime()==validTo.getTime()){
resource.delete();
}
}catch(ResourceExceptione){
// TODO Auto-generated catch block
e.printStackTrace();
}catch(WcmExceptione1){
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
logger.severe(TYPE,"End RepServiceAEKStop");
}
}