Skip to Content
0
Former Member
Dec 10, 2009 at 09:55 AM

tbp repository service

17 Views

I'm trying to create a new repository service but i´m having some trouble. I want to make a service that automatically runs when i upload a new document and it changes the validto date to three months ahead from the current date.

This is the code that i've built using some examples found in the forums but it's not working at all:

import java.util.Collection;

import java.util.Iterator;

import java.util.Date;

import java.util.Calendar;

import com.sapportals.wcm.repository.service.AbstractRepositoryService;

import com.sapportals.wcm.repository.service.IRepositoryService;

import com.sapportals.wcm.repository.service.ServiceNotAvailableException;

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

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

import com.sapportals.wcm.repository.service.IRepositoryServiceFactory;

import com.sapportals.wcm.repository.ResourceFactory;

import com.sapportals.wcm.repository.service.*;

import com.sapportals.wcm.repository.service.timebasedpublish.ITimebasedPublishServiceManager;

//import com.sapportals.wcm.repository.service.timebasedpublish;

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.IResourceEvent;

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

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

import com.sapportals.wcm.util.events.IEvent;

import com.sapportals.wcm.crt.component.*;

import com.sapportals.wcm.crt.configuration.*;

import com.sapportals.wcm.IWcmConst;

import com.sapportals.wcm.WcmException;

// implements IMyNewRepositoryService interface

/*

Note: IReconfigurable and IResourceEventReceiver interfaces are optional

*/

public class seskmTimeBasedRepository extends AbstractRepositoryService implements IReconfigurable, IResourceEventReceiver {

private static final String TYPE = "seskmTimeBasedRepository";

private Collection repositoryManagers;

public seskmTimeBasedRepository() {

super();

// Do not add code here. Add it to startUpImpl() instead

}

public String getServiceType() {

return seskmTimeBasedRepository.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 removeRepositoryAssignment(IRepositoryManager mgr) throws WcmException {

mgr.getEventBroker().unregister(this, ResourceEvent.GET_TEMPLATE);

}

public void reconfigure(IConfiguration arg0) throws ConfigurationException {}

public void received(IEvent event) {

IResourceEvent myEvent = (IResourceEvent) event;

try {

IResource res = myEvent.getResource();

IResource res2 = (IResource)myEvent.getParameter();

PropertyName propertyNameValidTo = new PropertyName("http://sapportals.com/xmlns/cm/tbp","VALIDTO");

Property propValidTo = new Property(propertyNameValidTo,new Integer(0));

IProperty oldValidTo = res.getProperty(propertyNameValidTo);

String sOldValidTo = oldValidTo.getValueAsString();

Date validTo = new Date(sOldValidTo);

int month = validTo.getMonth();

month +=3;

validTo.setMonth(month);

propValidTo = new Property(propertyNameValidTo,validTo);

res.setProperty(propValidTo);

IRepositoryServiceFactory repServiceFactory = ResourceFactory.getInstance().getServiceFactory();

IRepositoryService repositoryService = repServiceFactory.getRepositoryService(res,IWcmConst.TIMEBASED_PUBLISH_SERVICE);

ITimebasedPublishServiceManager tpbService =(ITimebasedPublishServiceManager) repositoryService;

java.util.Date startDate = new java.util.Date();

java.util.Date endDate = new java.util.Date();

//PropertyName propertyNameValidToT = new PropertyName("{http://sapportals.com/xmlns/cm/tbp}","VALIDTO");

PropertyName propertyNameValidToT = new PropertyName("http://sapportals.com/xmlns/cm/tbp","VALIDTO");

IProperty validToT = res.getProperty(propertyNameValidToT);

endDate.setMonth(startDate.getMonth() + 3);

tpbService.saveValidDate(res, startDate);

tpbService.saveInvalidDate(res, endDate);

} catch (ResourceException e) {

e.printStackTrace();

}

catch (WcmException e) {

e.printStackTrace();

}

}

protected void addRepositoryAssignment(IRepositoryManager mgr) throws ServiceNotAvailableException {

try {

mgr.getEventBroker().register(this, new ResourceEvent(ResourceEvent.CREATE_CHILD,null));

} catch (WcmException e) {

e.printStackTrace();

}

}

}

Any help, please?