Skip to content

Commit 4ca1c33

Browse files
Updated Spring version; maped root to swagger endpoint; fixed code style.
1 parent 8b69628 commit 4ca1c33

8 files changed

Lines changed: 85 additions & 81 deletions

File tree

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM openjdk:8-jdk-alpine
2+
VOLUME /tmp
3+
ARG JAR_FILE
4+
COPY ${JAR_FILE} app.jar
5+
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ the end of the `java -jar` command (see below), or set `SIFGRAPH_DATA` system va
1616

1717
Build:
1818

19-
```
19+
```commandline
2020
./gradlew build
2121
```
2222

2323
Run:
2424

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

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

36-
```
36+
```commandline
3737
java -jar build/libs/sifgraph-server.jar --spring.config.name=my
3838
```
3939

4040
RESTful API (Swagger docs):
4141

4242
Once the app is built and running,
4343
the auto-generated documentation is available at
44-
`http://localhost:8080/sifgraph/swagger-ui.html`
44+
`http://localhost:8080/sifgraph/`

build.gradle

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,61 @@
11
buildscript {
2+
ext {
3+
springBootVersion = '2.1.0.RELEASE'
4+
}
25
repositories {
3-
mavenCentral()
6+
maven {
7+
url "https://plugins.gradle.org/m2/"
8+
}
49
}
510
dependencies {
6-
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
11+
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
12+
classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.20.1"
713
}
814
}
915

1016
apply plugin: 'java'
1117
apply plugin: 'idea'
1218
apply plugin: 'org.springframework.boot'
1319
apply plugin: 'io.spring.dependency-management'
14-
15-
jar {
16-
baseName = 'sifgraph-server'
17-
version = '0.2.0'
18-
}
20+
apply plugin: 'com.palantir.docker'
1921

2022
repositories {
2123
mavenCentral()
22-
2324
maven {
2425
url "https://oss.sonatype.org/content/groups/public/"
2526
}
2627
}
2728

28-
sourceCompatibility = 1.8
29-
targetCompatibility = 1.8
30-
3129
dependencies {
32-
compile("org.springframework.boot:spring-boot-starter-web")
33-
// tag::actuator[]
34-
compile("org.springframework.boot:spring-boot-starter-actuator")
35-
// end::actuator[]
36-
// tag::tests[]
37-
testCompile("org.springframework.boot:spring-boot-starter-test")
38-
// end::tests[]
39-
40-
compile("pathwaycommons.sif:sifgraph:1.0.0-SNAPSHOT")
41-
42-
compileOnly("org.springframework.boot:spring-boot-devtools")
43-
44-
//can use the following instead 'compileOnly' since gradle 4.6:
45-
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
46-
47-
//Swagger and UI
48-
compile "io.springfox:springfox-swagger2:2.7.0"
49-
compile "io.springfox:springfox-swagger-ui:2.7.0"
30+
implementation 'pathwaycommons.sif:sifgraph:1.0.0-SNAPSHOT'
31+
32+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
33+
implementation 'org.springframework.boot:spring-boot-starter-web'
34+
implementation "org.springframework.boot:spring-boot-configuration-processor"
35+
implementation 'io.springfox:springfox-swagger2:2.7.0'
36+
implementation 'io.springfox:springfox-swagger-ui:2.7.0'
37+
38+
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
39+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
40+
41+
//java 9+ does not have Jax B Dependents
42+
implementation 'javax.xml.bind:jaxb-api:2.3.0'
43+
implementation 'com.sun.xml.bind:jaxb-core:2.3.0'
44+
implementation 'com.sun.xml.bind:jaxb-impl:2.3.0'
45+
implementation 'javax.activation:activation:1.1.1'
46+
}
5047

51-
//enable JSR-303
52-
// compile "io.springfox:springfox-bean-validators:2.7.0"
48+
sourceCompatibility = 1.8
49+
group = 'pathwaycommons'
50+
version = '0.3.0'
51+
52+
docker {
53+
dependsOn build
54+
name "${project.group}/${bootJar.baseName}"
55+
files bootJar.archivePath
56+
buildArgs(['JAR_FILE': "${bootJar.archiveName}"])
5357
}
5458

5559
task wrapper(type: Wrapper) {
56-
gradleVersion = '4.7'
60+
gradleVersion = '4.8.1'
5761
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri May 11 20:06:17 EDT 2018
1+
#Mon Nov 19 13:21:17 EST 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'sifgraph-server'

src/main/java/org/pathwaycommons/sif/server/Application.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.boot.context.properties.EnableConfigurationProperties;
66
import org.springframework.context.ApplicationContext;
7+
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
8+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
79

810
import java.io.IOException;
911

1012
@SpringBootApplication
1113
@EnableConfigurationProperties(SifgraphProperties.class)
12-
public class Application {
14+
public class Application implements WebMvcConfigurer {
1315

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

21+
@Override
22+
public void addViewControllers(ViewControllerRegistry registry) {
23+
registry.addRedirectViewController("/", "/swagger-ui.html");
24+
}
25+
1926
}
2027

src/main/java/org/pathwaycommons/sif/server/Controller.java

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public Controller(SifgraphProperties properties) {
4646
}
4747

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

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

83-
return write(result);
84-
} catch (Exception e) {
85-
throw new RuntimeException("/neighborhood failed: " + e);
86-
}
82+
return write(result);
8783
}
8884

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

109-
try {
110-
Set<Object> result = QueryExecutor.searchPathsBetween(graph,
111-
new RelationTypeSelector((pattern != null && pattern.length > 0) ? pattern : DEFAULT_RELS),
112-
sources, directed, limit);
105+
Set<Object> result = QueryExecutor.searchPathsBetween(graph,
106+
new RelationTypeSelector((pattern!=null && pattern.length>0)?pattern:DEFAULT_RELS),
107+
sources, directed, limit);
113108

114-
return write(result);
115-
} catch (Exception e) {
116-
throw new RuntimeException("/pathsbetween failed: " + e);
117-
}
109+
return write(result);
118110
}
119111

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

139-
try {
140-
Set<Object> result = QueryExecutor.searchCommonStream(graph,
141-
new RelationTypeSelector((pattern != null && pattern.length > 0) ? pattern : DEFAULT_RELS),
142-
sources, direction, limit);
131+
Set<Object> result = QueryExecutor.searchCommonStream(graph,
132+
new RelationTypeSelector((pattern!=null && pattern.length>0)?pattern:DEFAULT_RELS),
133+
sources, direction, limit);
143134

144-
return write(result);
145-
} catch (Exception e) {
146-
throw new RuntimeException("/commonstream failed: " + e);
147-
}
135+
return write(result);
148136
}
149137

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

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

172-
try {
173-
Set<Object> result = QueryExecutor.searchPathsFromTo(graph,
174-
new RelationTypeSelector((pattern != null && pattern.length > 0) ? pattern : DEFAULT_RELS),
175-
sources, targets, limit);
160+
Set<Object> result = QueryExecutor.searchPathsFromTo(graph,
161+
new RelationTypeSelector((pattern!=null && pattern.length>0) ? pattern:DEFAULT_RELS),
162+
sources, targets, limit);
176163

177-
return write(result);
178-
} catch (Exception e) {
179-
throw new RuntimeException("/pathsfromto failed: " + e);
180-
}
164+
return write(result);
181165
}
182166

183167
private String write(Set<Object> result) throws IOException {

src/main/resources/config/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
server.port=8080
22
server.servlet.context-path = /sifgraph
33
#server.error.whitelabel.enabled = false
4+
# * - enables all actuator endpoints
5+
management.endpoints.web.exposure.include=health,info
6+
#management.endpoints.web.exposure.exclude=
47

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

0 commit comments

Comments
 (0)