Sam Adams avatar Sam Adams committed 4d557b3

Initial commit

Comments (0)

Files changed (5)

+
+# maven
+^target/
+/target/
+
+# intellij
+^.idea/
+\.iml$
+
+# eclipse
+^\.classpath$
+/\.classpath$
+^\.project$
+/\.project$
+^\.settings/
+/\.settings/
+
+# temp files
+~$
+\.old$
+^temp/
+/temp/
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+
+    <parent>
+        <groupId>uk.ac.cam.ch.wwmm.chempound</groupId>
+        <artifactId>chempound-parent</artifactId>
+        <version>1-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>net.quixote</groupId>
+    <artifactId>quixote-webapp</artifactId>
+    <version>0.1-SNAPSHOT</version>
+    <packaging>war</packaging>
+
+    <name>Quixote Data Repository</name>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>uk.ac.cam.ch.wwmm.chempound</groupId>
+            <artifactId>chempound-webapp</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>uk.ac.cam.ch.wwmm.chempound.chemistry</groupId>
+            <artifactId>chemistry-search-structure</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>uk.ac.cam.ch.wwmm.chempound.chemistry</groupId>
+            <artifactId>chemistry-jmol-plugin</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>uk.ac.cam.ch.wwmm.chempound.plugins</groupId>
+            <artifactId>chempound-jquery-plugin</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>uk.ac.cam.ch.wwmm.chempound.crystallography</groupId>
+            <artifactId>crystallography-handler</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>uk.ac.cam.ch.wwmm.chempound.compchem</groupId>
+            <artifactId>compchem-handler</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>[1.6.1]</version>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.inject</groupId>
+            <artifactId>guice</artifactId>
+            <version>3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.inject.extensions</groupId>
+            <artifactId>guice-servlet</artifactId>
+            <version>3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.restlet.jee</groupId>
+            <artifactId>org.restlet</artifactId>
+            <version>2.0.7</version>
+        </dependency>
+        <dependency>
+            <groupId>org.restlet.jee</groupId>
+            <artifactId>org.restlet.ext.servlet</artifactId>
+            <version>2.0.7</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+
+            <plugin>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <configuration>
+                    <descriptorRefs>
+                        <descriptorRef>jar-with-dependencies</descriptorRef>
+                    </descriptorRefs>
+                    <archive>
+                        <manifest>
+                            <mainClass>quixote.chempound.ChempoundLauncher</mainClass>
+                        </manifest>
+                    </archive>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>make-assembly</id>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                        <phase>package</phase>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.mortbay.jetty</groupId>
+                <artifactId>maven-jetty-plugin</artifactId>
+                <version>6.1.26</version>
+                <configuration>
+                    <contextPath>/</contextPath>
+                    <scanIntervalSeconds>5</scanIntervalSeconds>
+                </configuration>
+            </plugin>
+
+        </plugins>
+    </build>
+
+</project>

src/main/java/uk/ac/cam/ch/wwmm/quixote/QuixoteChempoundServletConfig.java

+package uk.ac.cam.ch.wwmm.quixote;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.servlet.GuiceServletContextListener;
+import com.google.inject.servlet.ServletModule;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.tdb.TDBFactory;
+import org.apache.commons.io.FileUtils;
+import uk.ac.cam.ch.wwmm.chempound.ChempoundConfiguration;
+import uk.ac.cam.ch.wwmm.chempound.DefaultChempoundModule;
+import uk.ac.cam.ch.wwmm.chempound.comp.CompChemModule;
+import uk.ac.cam.ch.wwmm.chempound.crystal.CrystallographyModule;
+import uk.ac.cam.ch.wwmm.chempound.datastore.DataStore;
+import uk.ac.cam.ch.wwmm.chempound.datastore.TripleStore;
+import uk.ac.cam.ch.wwmm.chempound.storage.FileSystemResourceStore;
+import uk.ac.cam.ch.wwmm.chempound.storage.ResourceStore;
+import uk.ac.cam.ch.wwmm.chempound.webapp.DefaultFreemarkerService;
+import uk.ac.cam.ch.wwmm.chempound.webapp.FreemarkerService;
+import uk.ac.cam.ch.wwmm.chempound.webapp.search.chemistry.StructureSearchProviderModule;
+import uk.ac.cam.ch.wwmm.chempound.webapp.sword.impl.SwordModule;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+
+/**
+ * @author sea36
+ */
+public class QuixoteChempoundServletConfig extends GuiceServletContextListener {
+
+    private String workspace;
+    private String baseUri;
+
+    public QuixoteChempoundServletConfig() {
+        workspace = System.getProperty("chempound.workspace");
+        if (workspace == null) {
+            workspace = System.getenv("CHEMPOUND_WORKSPACE");
+        }
+        if (workspace == null) {
+            throw new RuntimeException("Chempound workspace not set");
+        }
+
+        baseUri = System.getProperty("chempound.uri");
+        if (baseUri == null) {
+            baseUri = System.getenv("CHEMPOUND_URI");
+        }
+        if (baseUri == null) {
+            throw new RuntimeException("Chempound base URI not set");
+        }
+    }
+
+    public QuixoteChempoundServletConfig(String workspace, String baseUri) {
+        this.workspace = workspace;
+        this.baseUri = baseUri;
+    }
+
+
+    private static DataStore createDataStore(ChempoundConfiguration config) throws IOException {
+        File dir = new File(config.getWorkspace(), "tdb/");
+        FileUtils.forceMkdir(dir);
+        Dataset dataset = TDBFactory.createDataset(dir.getPath());
+        return new DataStore(dataset);
+    }
+
+    private static ResourceStore createResourceStore(ChempoundConfiguration config) throws IOException {
+        File dir = new File(config.getWorkspace(), "content/");
+        FileUtils.forceMkdir(dir);
+        return new FileSystemResourceStore(dir);
+    }
+
+    private Module createConfigurationModule() {
+        return new AbstractModule() {
+            @Override
+            protected void configure() {
+                File workspaceDir = new File(workspace);
+                URI uri = URI.create(baseUri);
+                ChempoundConfiguration config = new ChempoundConfiguration(uri, workspaceDir);
+                bind(ChempoundConfiguration.class).toInstance(config);
+
+                try {
+                    TripleStore dataStore = createDataStore(config);
+                    ResourceStore resourceStore = createResourceStore(config);
+                    bind(TripleStore.class).toInstance(dataStore);
+                    bind(ResourceStore.class).toInstance(resourceStore);
+                } catch (IOException e) {
+                    throw new RuntimeException("Error initialising chempound", e);
+                }
+            }
+        };
+    }
+
+    protected Module createChempoundModule() {
+        return new DefaultChempoundModule();
+    }
+
+    protected ServletModule createServletModule() {
+        return new ServletModule() {
+            @Override
+            protected void configureServlets() {
+                bind(FreemarkerService.class).to(DefaultFreemarkerService.class);
+                serve("/*").with(QuixoteServlet.class);
+            }
+        };
+    }
+
+    @Override
+    protected Injector getInjector() {
+        return Guice.createInjector(
+                createConfigurationModule(),
+                createChempoundModule(),
+                createServletModule(),
+
+                new StructureSearchProviderModule(),
+                new CrystallographyModule(),
+                new CompChemModule(),
+
+                new SwordModule()
+        );
+    }
+
+}

src/main/java/uk/ac/cam/ch/wwmm/quixote/QuixoteServlet.java

+package uk.ac.cam.ch.wwmm.quixote;
+
+import com.google.inject.Injector;
+import org.restlet.Component;
+import org.restlet.Context;
+import org.restlet.data.Protocol;
+import org.restlet.ext.servlet.ServletAdapter;
+import uk.ac.cam.ch.wwmm.chempound.webapp.ChempoundApplication;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @author sea36
+ */
+@Singleton
+public class QuixoteServlet extends HttpServlet {
+
+    private Injector injector;
+    private ServletAdapter adapter;
+
+    @Inject
+    public QuixoteServlet(Injector injector) {
+        this.injector = injector;
+    }
+
+    @Override
+    public void init() throws ServletException {
+        final Component component = new Component();
+        component.getClients().add(Protocol.CLAP);
+
+        Context context = component.getContext().createChildContext();
+        ChempoundApplication application = new ChempoundApplication(injector, context);
+        this.adapter = new ServletAdapter(getServletContext(), application);
+    }
+
+    @Override
+    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+        adapter.service(req, resp);
+    }
+
+}

src/main/webapp/WEB-INF/web.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+    <display-name>Quixote Chempound</display-name>
+
+    <listener>
+        <listener-class>uk.ac.cam.ch.wwmm.quixote.QuixoteChempoundServletConfig</listener-class>
+    </listener>
+
+    <filter>
+        <filter-name>guiceFilter</filter-name>
+        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
+    </filter>
+
+    <filter-mapping>
+        <filter-name>guiceFilter</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+
+</web-app>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.