@Override
protected ReplicationRequest processEvent(Event event) throws RepositoryException {
log.debug("processing event {}", event);
ReplicationRequest replicationRequest = null;
Session session = getSession();
if (session != null && session.hasPermission(nuggetsPath, Privilege.JCR_ADD_CHILD_NODES)) {
log.debug("persisting event under {}", nuggetsPath);
Node nuggetsNode = session.getNode(nuggetsPath);
if (nuggetsNode != null) {
String nodeName = event.getIdentifier() != null ? event.getIdentifier() : String.valueOf(System.nanoTime());
Node createdNode = nuggetsNode.addNode(nodeName);
if (createdNode != null) {
String path = createdNode.getPath();
nuggetsNode.setProperty("path", event.getPath());
nuggetsNode.setProperty("date", event.getDate());
nuggetsNode.setProperty("type", event.getType());
nuggetsNode.setProperty("userData", event.getUserData());
nuggetsNode.setProperty("userID", event.getUserID());
Set<Map.Entry> set = event.getInfo().entrySet();
for (Map.Entry entry : set) {
nuggetsNode.setProperty("info." + entry.getKey(), String.valueOf(entry.getValue()));
}
session.save();
log.debug("event persisted at {}", path);
replicationRequest = new ReplicationRequest(System.currentTimeMillis(), ReplicationActionType.ADD, path);
} else {
log.warn("could not create node {}", nuggetsPath + "/" + nodeName);
}
} else {
log.warn("could not get node {} to persist event", nuggetsPath);