Skip to content

Commit

Permalink
Demo for examination
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Apr 17, 2013
0 parents commit c116597
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
@@ -0,0 +1,13 @@
target/
.classpath
.settings/
.project
.metadata
ActiveMQ/
FedoraRepository/
indexes/
ObjectStore/
*/.cache
.cache
.DS_Store
*~
55 changes: 55 additions & 0 deletions pom.xml
@@ -0,0 +1,55 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>demo</groupId>
<artifactId>node-goes-from-federated-to-ispn</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.modeshape</groupId>
<artifactId>modeshape-jcr</artifactId>
<version>3.2-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<debug>false</debug>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>demo.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>fcrepo-snapshot</id>
<name>Fcrepo Repository for Maven</name>
<url>http://maven.fcrepo.org/nexus/content/repositories/snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
94 changes: 94 additions & 0 deletions src/main/java/demo/Main.java
@@ -0,0 +1,94 @@

package demo;

import static java.lang.System.exit;
import static java.lang.System.out;
import static org.modeshape.jcr.RepositoryConfiguration.read;

import java.util.concurrent.ExecutionException;

import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Workspace;

import org.infinispan.schematic.document.ParsingException;
import org.modeshape.jcr.ConfigurationException;
import org.modeshape.jcr.JcrRepository;
import org.modeshape.jcr.ModeShapeEngine;
import org.modeshape.jcr.NoSuchRepositoryException;
import org.modeshape.jcr.api.JcrTools;

public class Main {

static Main me = new Main();

ModeShapeEngine engine = new ModeShapeEngine();

JcrRepository repo;

private final String repoName = "repo";

private final static String repoConfig = "/repository.json";

public static void main(String[] args) {
try {
me.start();
Session session = me.repo.login();

setup: {
session.getRootNode().addNode("nonfederated");
new JcrTools(true).uploadFileAndBlock(session, Main.class
.getResource("/thing2"), "/nonfederated");
}

action: {
final Workspace ws = session.getWorkspace();
ws.copy("/p1/thing1", "/nonfederated/thing1");
session.removeItem("/p1/thing1");
ws.copy("/nonfederated/thing2", "/p1/thing2");
session.removeItem("/nonfederated/thing2");
}

session.save();
session.logout();
session = me.repo.login();

tests: {
assert !session.nodeExists("/p1/thing1") : "Shouldn't find /p1/thing1!";
assert session.nodeExists("/nonfederated/thing1") : "Should find /nonfederated/thing1!";
assert !session.nodeExists("/nonfederated/thing2") : "Shouldn't find /nonfederated/thing2!";
assert session.nodeExists("/p1/thing2") : "Should find /p1/thing2!";
}

session.save();
session.logout();
me.stop();

} catch (Exception e) {
e.printStackTrace();
exit(1);
}
exit(0);

}

private void start() throws ConfigurationException, ParsingException,
RepositoryException {
engine.start();
out.println("Engine started...");
engine.deploy(read(this.getClass().getResource(repoConfig)));
out.println("Repo deployed...");
engine.startRepository(repoName);
out.println("Repo started...");
repo = engine.getRepository(repoName);
}

private void stop() throws NoSuchRepositoryException, InterruptedException,
ExecutionException {
// block waiting for all repos to shutdown
out.println("Engine stopping...");
engine.shutdown().get();
out.println("Engine stopped.");
}

}
26 changes: 26 additions & 0 deletions src/main/resources/repository.json
@@ -0,0 +1,26 @@
{
"name": "repo",
"workspaces": {
"predefined": [],
"default": "default",
"allowCreation": false
},
"externalSources": {"targetDirectory": {
"classname": "org.modeshape.connector.filesystem.FileSystemConnector",
"directoryPath": "target/classes/test-objects",
"readonly": false,
"cacheTtlSeconds": 1,
"projections": ["default:/p1 => /"]
}},
"security": {
"anonymous": {
"roles": [
"readonly",
"readwrite",
"admin"
],
"useOnFailedLogin": false
},
"providers": [{"classname": "servlet"}]
}
}
1 change: 1 addition & 0 deletions src/main/resources/test-objects/thing1/foo
@@ -0,0 +1 @@
foo
1 change: 1 addition & 0 deletions src/main/resources/thing2
@@ -0,0 +1 @@
flambeau

0 comments on commit c116597

Please sign in to comment.