Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved fcrepo-kernel injection patterns
- Loading branch information
Showing
12 changed files
with
176 additions
and
107 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
fcrepo-kernel/src/main/java/org/fcrepo/eventing/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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
package org.fcrepo.eventing; | ||
|
||
import static com.google.common.collect.Iterables.any; | ||
import static com.google.common.collect.Sets.newHashSet; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.enterprise.inject.Default; | ||
import javax.inject.Inject; | ||
import javax.jcr.LoginException; | ||
import javax.jcr.PathNotFoundException; | ||
import javax.jcr.Repository; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.jcr.nodetype.NodeType; | ||
import javax.jcr.observation.Event; | ||
|
||
import org.modeshape.common.SystemFailureException; | ||
|
||
import com.google.common.base.Predicate; | ||
|
||
@Default | ||
public class DefaultFilter implements EventFilter { | ||
|
||
@Inject | ||
private Repository repository; | ||
|
||
// it's safe to keep the session around, because this code does not mutate | ||
// the state of the repository | ||
private Session session; | ||
|
||
private Predicate<NodeType> isFedoraNodeType = new Predicate<NodeType>() { | ||
|
||
@Override | ||
public boolean apply(NodeType type) { | ||
return type.getName().startsWith("fedora:"); | ||
} | ||
}; | ||
|
||
@Override | ||
public boolean apply(Event event) { | ||
|
||
try { | ||
return any(newHashSet(session.getNode(event.getPath()) | ||
.getMixinNodeTypes()), isFedoraNodeType); | ||
|
||
} catch (PathNotFoundException e) { | ||
return false; // not a node in the fedora workspace | ||
} catch (LoginException e) { | ||
throw new SystemFailureException(e); | ||
} catch (RepositoryException e) { | ||
throw new SystemFailureException(e); | ||
} | ||
} | ||
|
||
@PostConstruct | ||
public void acquireSession() { | ||
try { | ||
session = repository.login(); | ||
} catch (RepositoryException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
@PreDestroy | ||
public void releaseSession() { | ||
session.logout(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...java/org/fcrepo/observer/EventFilter.java → ...java/org/fcrepo/eventing/EventFilter.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,4 +1,4 @@ | ||
package org.fcrepo.observer; | ||
package org.fcrepo.eventing; | ||
|
||
import javax.jcr.observation.Event; | ||
|
||
|
21 changes: 21 additions & 0 deletions
21
fcrepo-kernel/src/main/java/org/fcrepo/eventing/FedoraEventBus.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,21 @@ | ||
|
||
package org.fcrepo.eventing; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.common.eventbus.EventBus; | ||
|
||
@Singleton | ||
public class FedoraEventBus extends EventBus { | ||
|
||
final private Logger logger = LoggerFactory.getLogger(FedoraEventBus.class); | ||
|
||
public FedoraEventBus() { | ||
super(); | ||
logger.debug("Created Fedora event bus."); | ||
} | ||
|
||
} |
4 changes: 3 additions & 1 deletion
4
.../java/org/fcrepo/observer/NOOPFilter.java → .../java/org/fcrepo/eventing/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
4 changes: 2 additions & 2 deletions
4
...a/org/fcrepo/observer/SimpleObserver.java → ...a/org/fcrepo/eventing/SimpleObserver.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
20 changes: 20 additions & 0 deletions
20
fcrepo-kernel/src/main/java/org/fcrepo/jcr/DefaultConfiguration.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,20 @@ | ||
package org.fcrepo.jcr; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Default; | ||
import javax.enterprise.inject.Produces; | ||
|
||
@ApplicationScoped | ||
@Default | ||
public class DefaultConfiguration { | ||
|
||
@Produces | ||
@ModeShapeRepositoryConfiguration | ||
public URL getConfiguration() throws MalformedURLException { | ||
return this.getClass().getResource("/repository.json"); | ||
} | ||
|
||
} |
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
62 changes: 0 additions & 62 deletions
62
fcrepo-kernel/src/main/java/org/fcrepo/observer/DefaultFilter.java
This file was deleted.
Oops, something went wrong.
Empty file.
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
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,2 @@ | ||
pax.exam.system = cdi | ||
pax.exam.logging = none |
File renamed without changes.