Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now with two event filter implementations. NOOP does nothing, Default…
… looks only at nodes with a mixin type in the fedora namespace
- Loading branch information
Showing
3 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
60 changes: 58 additions & 2 deletions
60
src/main/java/org/fcrepo/modeshape/observer/DefaultFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,66 @@ | ||
package org.fcrepo.modeshape.observer; | ||
|
||
import java.util.Set; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.inject.Inject; | ||
import javax.jcr.LoginException; | ||
import javax.jcr.Node; | ||
import javax.jcr.PathNotFoundException; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.jcr.nodetype.NodeType; | ||
import javax.jcr.observation.Event; | ||
|
||
import org.modeshape.common.SystemFailureException; | ||
import org.modeshape.jcr.api.Repository; | ||
|
||
import com.google.common.base.Predicate; | ||
import com.google.common.collect.Iterables; | ||
import com.google.common.collect.Sets; | ||
|
||
public class DefaultFilter implements EventFilter { | ||
|
||
@Inject | ||
private Repository repository; | ||
|
||
// it's safe to keep the session around, because this is a non-mutating actor | ||
private Session session; | ||
|
||
@Override | ||
public boolean apply(Event event) { | ||
return true; | ||
Predicate<NodeType> isFedoraNodeType = new Predicate<NodeType>() { | ||
@Override | ||
public boolean apply(NodeType type) { | ||
return type.getName().startsWith("fedora:"); | ||
} | ||
}; | ||
|
||
try { | ||
Node node = null; | ||
try { | ||
node = session.getNode(event.getPath()); | ||
} catch (PathNotFoundException e) { | ||
return false; // not a node in the fedora workspace | ||
} | ||
Set<NodeType> types = Sets.newHashSet(node.getMixinNodeTypes()); | ||
return Iterables.any(types, isFedoraNodeType); | ||
|
||
} catch (LoginException e) { | ||
throw new SystemFailureException(e); | ||
} catch (RepositoryException e) { | ||
throw new SystemFailureException(e); | ||
} | ||
} | ||
|
||
@PostConstruct | ||
public void acquireSession() throws LoginException, RepositoryException { | ||
session = repository.login(); | ||
} | ||
|
||
@PreDestroy | ||
public void releaseSession() { | ||
session.logout(); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/fcrepo/modeshape/observer/NOOPFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.fcrepo.modeshape.observer; | ||
|
||
import javax.jcr.observation.Event; | ||
|
||
public class NOOPFilter implements EventFilter { | ||
@Override | ||
public boolean apply(Event event) { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters