Skip to content

Commit

Permalink
Updated Spring version; maped root to swagger endpoint; fixed code st…
Browse files Browse the repository at this point in the history
…yle.
  • Loading branch information
IgorRodchenkov committed Nov 20, 2018
1 parent 8b69628 commit 4ca1c33
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 81 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ the end of the `java -jar` command (see below), or set `SIFGRAPH_DATA` system va

Build:

```
```commandline
./gradlew build
```

Run:

```
java -jar build/libs/sifgraph-server.jar --sifgraph.data="file:path/to/graph.txt.gz" --server.port=8080
```commandline
java -jar build/libs/sifgraph-server-0.3.0.jar -Xmx4g --sifgraph.data="file:/path/to/graph.txt.gz" --server.port=8080
```

Note: override the default list of SIF patterns using `--sifgraph.relationships=...` if needed (depends on the data).
Expand All @@ -33,12 +33,12 @@ copy src/main/resources/config/application.properties to the work/current direct
rename (e.g., my.properties), modify (e.g., set another `server.port`, `sifgraph.relationships`
and `sifgraph.data` file), and run as:

```
```commandline
java -jar build/libs/sifgraph-server.jar --spring.config.name=my
```

RESTful API (Swagger docs):

Once the app is built and running,
the auto-generated documentation is available at
`http://localhost:8080/sifgraph/swagger-ui.html`
`http://localhost:8080/sifgraph/`
68 changes: 36 additions & 32 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,57 +1,61 @@
buildscript {
ext {
springBootVersion = '2.1.0.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.20.1"
}
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

jar {
baseName = 'sifgraph-server'
version = '0.2.0'
}
apply plugin: 'com.palantir.docker'

repositories {
mavenCentral()

maven {
url "https://oss.sonatype.org/content/groups/public/"
}
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
// tag::tests[]
testCompile("org.springframework.boot:spring-boot-starter-test")
// end::tests[]

compile("pathwaycommons.sif:sifgraph:1.0.0-SNAPSHOT")

compileOnly("org.springframework.boot:spring-boot-devtools")

//can use the following instead 'compileOnly' since gradle 4.6:
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"

//Swagger and UI
compile "io.springfox:springfox-swagger2:2.7.0"
compile "io.springfox:springfox-swagger-ui:2.7.0"
implementation 'pathwaycommons.sif:sifgraph:1.0.0-SNAPSHOT'

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation "org.springframework.boot:spring-boot-configuration-processor"
implementation 'io.springfox:springfox-swagger2:2.7.0'
implementation 'io.springfox:springfox-swagger-ui:2.7.0'

runtimeOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

//java 9+ does not have Jax B Dependents
implementation 'javax.xml.bind:jaxb-api:2.3.0'
implementation 'com.sun.xml.bind:jaxb-core:2.3.0'
implementation 'com.sun.xml.bind:jaxb-impl:2.3.0'
implementation 'javax.activation:activation:1.1.1'
}

//enable JSR-303
// compile "io.springfox:springfox-bean-validators:2.7.0"
sourceCompatibility = 1.8
group = 'pathwaycommons'
version = '0.3.0'

docker {
dependsOn build
name "${project.group}/${bootJar.baseName}"
files bootJar.archivePath
buildArgs(['JAR_FILE': "${bootJar.archiveName}"])
}

task wrapper(type: Wrapper) {
gradleVersion = '4.7'
gradleVersion = '4.8.1'
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri May 11 20:06:17 EDT 2018
#Mon Nov 19 13:21:17 EST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'sifgraph-server'
9 changes: 8 additions & 1 deletion src/main/java/org/pathwaycommons/sif/server/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.IOException;

@SpringBootApplication
@EnableConfigurationProperties(SifgraphProperties.class)
public class Application {
public class Application implements WebMvcConfigurer {

public static void main(String[] args) throws IOException {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
((Controller)ctx.getBean("controller")).init();
}

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/", "/swagger-ui.html");
}

}

66 changes: 25 additions & 41 deletions src/main/java/org/pathwaycommons/sif/server/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Controller(SifgraphProperties properties) {
}

@PostConstruct
void init() throws IOException {
protected void init() throws IOException {
final EdgeAnnotationType[] annotationTypes = props.getAnnotations();
sifWriter = new org.pathwaycommons.sif.io.Writer(false, annotationTypes);
InputStream is = new GZIPInputStream(resourceLoader.getResource(props.getData()).getInputStream());
Expand All @@ -69,21 +69,17 @@ public String nhood(
@ApiParam("Set of gene identifiers (HGNC Symbol) - 'seeds' for the graph traversal algorithm.")
@RequestParam(required = true) String[] source,
@ApiParam("Filter by binary relationship (SIF edge) type(s)")
@RequestParam(required = false) RelationTypeEnum[] pattern
) {
@RequestParam(required = false) RelationTypeEnum[] pattern) throws IOException
{
Set<String> sources = new HashSet();
for (String s : source)
sources.add(s);

pattern = (pattern != null && pattern.length > 0) ? pattern : DEFAULT_RELS;
try {
Set<Object> result = QueryExecutor.searchNeighborhood(graph,
new RelationTypeSelector(pattern), sources, direction, limit);
Set<Object> result = QueryExecutor.searchNeighborhood(graph,
new RelationTypeSelector((pattern!=null && pattern.length>0)?pattern:DEFAULT_RELS),
sources, direction, limit);

return write(result);
} catch (Exception e) {
throw new RuntimeException("/neighborhood failed: " + e);
}
return write(result);
}

@RequestMapping(path = "/pathsbetween")
Expand All @@ -100,21 +96,17 @@ public String pathsbetween(
@ApiParam("A set of gene identifiers.")
@RequestParam(required = true) String[] source,
@ApiParam("Filter by binary relationship (SIF edge) type(s)")
@RequestParam(required = false) RelationTypeEnum[] pattern
) {
@RequestParam(required = false) RelationTypeEnum[] pattern) throws IOException
{
Set<String> sources = new HashSet();
for (String s : source)
sources.add(s);

try {
Set<Object> result = QueryExecutor.searchPathsBetween(graph,
new RelationTypeSelector((pattern != null && pattern.length > 0) ? pattern : DEFAULT_RELS),
sources, directed, limit);
Set<Object> result = QueryExecutor.searchPathsBetween(graph,
new RelationTypeSelector((pattern!=null && pattern.length>0)?pattern:DEFAULT_RELS),
sources, directed, limit);

return write(result);
} catch (Exception e) {
throw new RuntimeException("/pathsbetween failed: " + e);
}
return write(result);
}

@RequestMapping(path = "/commonstream")
Expand All @@ -131,20 +123,16 @@ public String commonstream(
@ApiParam("A set of gene identifiers.")
@RequestParam(required = true) String[] source,
@ApiParam("Filter by binary relationship (SIF edge) type(s)")
@RequestParam(required = false) RelationTypeEnum[] pattern
) {
@RequestParam(required = false) RelationTypeEnum[] pattern) throws IOException
{
Set<String> sources = new HashSet();
for (String s : source) sources.add(s);

try {
Set<Object> result = QueryExecutor.searchCommonStream(graph,
new RelationTypeSelector((pattern != null && pattern.length > 0) ? pattern : DEFAULT_RELS),
sources, direction, limit);
Set<Object> result = QueryExecutor.searchCommonStream(graph,
new RelationTypeSelector((pattern!=null && pattern.length>0)?pattern:DEFAULT_RELS),
sources, direction, limit);

return write(result);
} catch (Exception e) {
throw new RuntimeException("/commonstream failed: " + e);
}
return write(result);
}

@RequestMapping(path = "/pathsfromto")
Expand All @@ -161,23 +149,19 @@ public String pathsfromto(
@ApiParam("A target set of gene identifiers.")
@RequestParam(required = true) String[] target,
@ApiParam("Filter by binary relationship (SIF edge) type(s)")
@RequestParam(required = false) RelationTypeEnum[] pattern
) {
@RequestParam(required = false) RelationTypeEnum[] pattern) throws IOException
{
Set<String> sources = new HashSet();
for (String s : source) sources.add(s);

Set<String> targets = new HashSet();
for (String s : target) targets.add(s);

try {
Set<Object> result = QueryExecutor.searchPathsFromTo(graph,
new RelationTypeSelector((pattern != null && pattern.length > 0) ? pattern : DEFAULT_RELS),
sources, targets, limit);
Set<Object> result = QueryExecutor.searchPathsFromTo(graph,
new RelationTypeSelector((pattern!=null && pattern.length>0) ? pattern:DEFAULT_RELS),
sources, targets, limit);

return write(result);
} catch (Exception e) {
throw new RuntimeException("/pathsfromto failed: " + e);
}
return write(result);
}

private String write(Set<Object> result) throws IOException {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
server.port=8080
server.servlet.context-path = /sifgraph
#server.error.whitelabel.enabled = false
# * - enables all actuator endpoints
management.endpoints.web.exposure.include=health,info
#management.endpoints.web.exposure.exclude=

# data location (Pathway Commons Extended SIF format)
#"http://www.pathwaycommons.org/archives/PC2/v10/PathwayCommons10.All.hgnc.txt.gz"
Expand Down

0 comments on commit 4ca1c33

Please sign in to comment.