Skip to content

Commit

Permalink
adding repository option as command line
Browse files Browse the repository at this point in the history
  • Loading branch information
ddtxra committed Jun 15, 2015
1 parent d68da88 commit e5c087d
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 17 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ There are some scenarios predefined:

* You can create your own scenario by giving a directory as argument: `java -jar sparql-playgroud.war your-directory-name`


Your directory should follow this convention:

* ttl-data: a folder containing turtle file(s)
* queries: a folder containing the queries showed in the first page
* prefixes.ttl: a file containing the default prefixes (optional) to be added to queries
* queries: a folder containing the example queries showed in the first page
* prefixes.ttl: a file containing the default prefixes to be added to queries
* pages: pages with markdown files for the Documentation tab
* config.properties - optionally you can include this property file with: repository.type=native to create a native repository (instead of in memory). This is particulary useful if your dataset contains more than 100'000 triplets

If you like you can share your dataset with us.
Notes:

* If your dataset is reasonably large that can't be fit in memory (> 50'000 triples) you may want to add the property `-Drepository.type=native`. This will create a native repository (instead of a in memory datastore). The database will be persisted in a `sesame-db` folder. The first time it will take some time to create the structure, but once the application is restarted it will be instantaneous.

* For development purposes you may want to set the java property `-Dspring.profiles.active=nocache` so the cache is not enabled (example queries, page, images, faqs ...)

##Technology in use
* The SPARQL engine is Sesame 2.7.9
Expand Down
1 change: 0 additions & 1 deletion nextprot/config.properties

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/ch/isb/sib/sparql/tutorial/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;

Expand All @@ -15,7 +14,6 @@
* @author Daniel Teixeira http://github.com/ddtxra
*
*/
@EnableCaching
@SpringBootApplication
public class Application {

Expand All @@ -25,12 +23,14 @@ public class Application {

public static void main(String[] args) {


if (args.length > 0) {
FOLDER = args[0];
}
logger.info("Reading from " + FOLDER);

SpringApplication.run(Application.class, args);

String port = null;
if (System.getProperty("server.port") == null) {
port = "8080";
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/ch/isb/sib/sparql/tutorial/CacheConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ch.isb.sib.sparql.tutorial;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
* Cache is enabled with the profile cache
* @author Daniel Teixeira http://github.com/ddtxra
*/
@Configuration
@EnableCaching
@Profile("!nocache")
public class CacheConfiguration {


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package ch.isb.sib.sparql.tutorial.controller;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -12,6 +15,7 @@

import ch.isb.sib.sparql.tutorial.Application;
import ch.isb.sib.sparql.tutorial.service.PageService;
import ch.isb.sib.sparql.tutorial.utils.IOUtils;

/**
* Controller used to serve markdown pages (and images) located under pages folder
Expand Down Expand Up @@ -39,5 +43,18 @@ public String page(@PathVariable("folder") String folder, @PathVariable("page")
return pageService.getFileOrTry(Application.FOLDER + "/pages/assets/" + asset + "." + extension, "assets/" + asset + "." + extension, extension);
}



@RequestMapping(value = "/assets/{asset}.pdf")
public void pdfDownload(@PathVariable("asset") String asset, HttpServletResponse response) throws IOException {
// set headers for the response
String headerKey = "Content-Disposition";
String headerValue = String.format("attachment; filename=\"%s\"", asset);
response.setHeader(headerKey, headerValue);

IOUtils.streamFile(new File("assets/" + asset + ".pdf"), response.getOutputStream());

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,7 @@ public void query(String queryString, TupleQueryResultHandler handler) {
@PostConstruct
public void init() throws Exception {

Properties prop = new Properties();
File configFile = new File(Application.FOLDER + "/config.properties");
if (configFile.exists()) {
InputStream input = null;
input = new FileInputStream(configFile);
prop.load(input);
}

boolean nativeConfig = prop.containsKey("repository.type") && prop.get("repository.type").equals("native");
boolean nativeConfig = (System.getProperty("repository.type") != null) && (System.getProperty("repository.type").equals("native"));
if(nativeConfig){
logger.info("Found repository type native property!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ private Object buildPage(File f, String name) {

@Cacheable("page")
public String getPage(String page) {
if(page.equals(ABOUT_PAGE)){
System.err.println("Getting page");

if(page.equals(ABOUT_PAGE)){
return IOUtils.readFile("README.md", null);
}else {
return IOUtils.readFile(Application.FOLDER + "/pages/" + page + ".md", null);
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/ch/isb/sib/sparql/tutorial/utils/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down Expand Up @@ -38,6 +39,7 @@ public static String readFile(String path, String orValue) {
public static byte[] readImage(String extension, File f) {

try {

// Retrieve image from the classpath.
InputStream is = new FileInputStream(f);

Expand All @@ -55,5 +57,29 @@ public static byte[] readImage(String extension, File f) {
throw new SparqlTutorialException(e);
}
}


public static void streamFile(File file, OutputStream outStream) {

try {

FileInputStream inputStream = new FileInputStream(file);

byte[] buffer = new byte[4096];
int bytesRead = -1;

// write bytes read from the input stream into the output stream
while ((bytesRead = inputStream.read(buffer)) != -1) {
outStream.write(buffer, 0, bytesRead);
}

inputStream.close();
outStream.close();
} catch (IOException e) {
throw new SparqlTutorialException(e);
}
}



}

0 comments on commit e5c087d

Please sign in to comment.