Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Just moving some duplicate methods into a utils package.
  • Loading branch information
ajs6f committed Feb 7, 2013
1 parent bae91c7 commit 747715b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 76 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/fcrepo/modeshape/AbstractResource.java
Expand Up @@ -15,6 +15,7 @@

import org.codehaus.jackson.map.ObjectMapper;
import org.fcrepo.modeshape.identifiers.PidMinter;
import org.fcrepo.modeshape.utils.Constants;
import org.modeshape.jcr.api.JcrTools;
import org.modeshape.jcr.api.Repository;
import org.slf4j.Logger;
Expand Down
@@ -1,5 +1,7 @@
package org.fcrepo.modeshape.modules.audit;

import static org.fcrepo.modeshape.utils.EventType.getEventName;

import javax.jcr.RepositoryException;
import javax.jcr.observation.Event;

Expand All @@ -10,60 +12,20 @@

/**
* A proof-of-concept Auditor implementation that uses Logback.
*
*
* @author Edwin Shin
*/
public class LogbackAuditor implements Auditor {

Logger logger = LoggerFactory.getLogger(LogbackAuditor.class);
Logger logger = LoggerFactory.getLogger(LogbackAuditor.class);

/**
/**
*
*/
@Override
@Subscribe
public void recordEvent(Event e) throws RepositoryException {
logger.info(e.getUserID() + " " + getEventName(e.getType()) + " " +
e.getPath());
}

/**
* Static utility method to retrieve a String representation of the type
* defined by a {@link javax.jcr.observation.Event JCR event}.
*
* @param jcrEvent
* @return Event name of the given JCR event type.
* @throws IllegalArgumentException if the given int does not represent a
* valid type constants as defined by {@link Event}.<br>
*/
private static String getEventName(int jcrEvent) {
String eventName;
switch (jcrEvent) {
case Event.NODE_ADDED:
eventName = "node added";
break;
case Event.NODE_REMOVED:
eventName = "node removed";
break;
case Event.PROPERTY_ADDED:
eventName = "property added";
break;
case Event.PROPERTY_CHANGED:
eventName = "property changed";
break;
case Event.PROPERTY_REMOVED:
eventName = "property removed";
break;
case Event.NODE_MOVED:
eventName = "node moved";
break;
case Event.PERSIST:
eventName = "persist";
break;
default: // no default
throw new IllegalArgumentException("Invalid JCR event type: " +
jcrEvent);
}
return eventName;
}
@Override
@Subscribe
public void recordEvent(Event e) throws RepositoryException {
logger.info(e.getUserID() + " " + getEventName(e.getType()) + " "
+ e.getPath());
}
}
28 changes: 2 additions & 26 deletions src/main/java/org/fcrepo/modeshape/observer/RSSPublisher.java
Expand Up @@ -2,6 +2,7 @@

import static com.google.common.collect.ImmutableList.copyOf;
import static com.google.common.collect.Lists.transform;
import static org.fcrepo.modeshape.utils.EventType.getEventType;

import java.io.ByteArrayInputStream;
import java.util.concurrent.ArrayBlockingQueue;
Expand Down Expand Up @@ -80,8 +81,7 @@ public SyndEntry apply(Event event) {
entry.setPublishedDate(new DateTime(event.getDate()).toDate());
SyndContent description = new SyndContentImpl();
description.setType("text/plain");
description.setValue(EventType.getEventType(event.getType())
.toString());
description.setValue(getEventType(event.getType()).toString());
entry.setDescription(description);
} catch (RepositoryException e) {
throw new SystemFailureException(e);
Expand All @@ -91,30 +91,6 @@ public SyndEntry apply(Event event) {

};

public enum EventType {
NODE_ADDED, NODE_REMOVED, PROPERTY_ADDED, PROPERTY_REMOVED, PROPERTY_CHANGED, NODE_MOVED, PERSIST;

public static EventType getEventType(Integer i) {
switch (i) {
case 0x1:
return NODE_ADDED;
case 0x2:
return NODE_REMOVED;
case 0x4:
return PROPERTY_ADDED;
case 0x8:
return PROPERTY_REMOVED;
case 0x10:
return PROPERTY_CHANGED;
case 0x20:
return NODE_MOVED;
case 0x40:
return PERSIST;
}
return null;
}
}

@PostConstruct
public void initialize() {
eventBus.register(this);
Expand Down
@@ -1,4 +1,4 @@
package org.fcrepo.modeshape;
package org.fcrepo.modeshape.utils;

import static javax.ws.rs.core.Response.status;
import static javax.ws.rs.core.Response.Status.FORBIDDEN;
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/org/fcrepo/modeshape/utils/EventType.java
@@ -0,0 +1,53 @@
package org.fcrepo.modeshape.utils;

import javax.jcr.observation.Event;

public enum EventType {
NODE_ADDED, NODE_REMOVED, PROPERTY_ADDED, PROPERTY_REMOVED, PROPERTY_CHANGED, NODE_MOVED, PERSIST;

public static EventType getEventType(Integer i) {
switch (i) {
case 0x1:
return NODE_ADDED;
case 0x2:
return NODE_REMOVED;
case 0x4:
return PROPERTY_ADDED;
case 0x8:
return PROPERTY_REMOVED;
case 0x10:
return PROPERTY_CHANGED;
case 0x20:
return NODE_MOVED;
case 0x40:
return PERSIST;

default: // no default
throw new IllegalArgumentException("Invalid JCR event type: " + i);
}
}

public static String getEventName(int jcrEvent) {

switch (getEventType(jcrEvent)) {
case NODE_ADDED:
return "node added";
case NODE_REMOVED:
return "node removed";
case PROPERTY_ADDED:
return "property added";
case PROPERTY_CHANGED:
return "property changed";
case PROPERTY_REMOVED:
return "property removed";
case NODE_MOVED:
return "node moved";
case PERSIST:
return "persist";

default: // no default
throw new IllegalArgumentException("Invalid JCR event type: "
+ jcrEvent);
}
}
}

0 comments on commit 747715b

Please sign in to comment.