Skip to content

Commit

Permalink
Slightly updated POM, readme, integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorRodchenkov committed Nov 19, 2023
1 parent b72c61e commit 31f1c60
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 73 deletions.
49 changes: 24 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

A convenient Java library to work with Pathway Commons web services.

We've just cut the cpath-client module from the cpath2 multi-module Maven project, refatored and moved here to make possible maintaining it separately from the server code (cpath2).
We've just cut the cpath-client module from the cpath2 multimodule Maven project, refatored and moved here to make possible maintaining it separately from the server code (cpath2).

This ia a fluent API Java client library for using Pathway Commons' RESTful [web services](http://www.pathwaycommons.org/pc2/), our large integrated BioPAX L3 database, from other Java projects, such as Cytoscape desctop (apps). But feel free to use another tool or develop own web client for Pathway Commons if you wish.
This ia a fluent API Java client library for using Pathway Commons' RESTful [web services](https://www.pathwaycommons.org/pc2/), our large integrated BioPAX L3 database, from other Java projects, such as Cytoscape desctop (apps). But feel free to use another tool or develop own web client for Pathway Commons if you wish.

# Use #
## Use

```
//using the Pathway Commons cPath2 web service URL (default):
Expand All @@ -19,33 +19,32 @@ CPathClient client = CPathClient.newInstance();
in a Maven project, add to the pom.xml the following:

```
<repositories>
<repository>
<id>ossrh</id>
<name>OSSRH Repository</name>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<repositories>
<repository>
<id>ossrh</id>
<name>OSSRH Repository</name>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>pathwaycommons.cpath</groupId>
<artifactId>cpath-client</artifactId>
<version>10.0.1-SNAPSHOT</version>
<groupId>pathwaycommons.cpath</groupId>
<artifactId>cpath-client</artifactId>
<version>10.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.biopax.paxtools</groupId>
<artifactId>paxtools-core</artifactId>
<version>5.3.0-SNAPSHOT</version>
<groupId>org.biopax.paxtools</groupId>
<artifactId>paxtools-core</artifactId>
<version>5.3.0</version>
</dependency>
</dependencies>
</dependencies>
```

See also:
* the project's [tests](https://github.com/PathwayCommons/cpath2-client/blob/master/src/test/java/cpath/client/CPathClientTest.java) can be used as example;
## See also:
* http://www.biopax.org/paxtools
* [tests](https://github.com/PathwayCommons/cpath2-client/blob/master/src/test/java/cpath/client/CPathClientIT.java) as an example;

Alternatively, one can add the cpath-client _fat_ jar with dependencies to a Java (or JPype) project: grab the latest fat-jar ([from here](https://oss.sonatype.org/content/groups/public/pathwaycommons/cpath/cpath-client/)).
One can add the cpath-client _fat_ jar with dependencies to a Java (or JPype) project: grab the latest fat-jar ([from here](https://oss.sonatype.org/content/groups/public/pathwaycommons/cpath/cpath-client/)).


# See also #
* http://www.biopax.org/paxtools

## ToDo:
* Implement cPath2 v14 APIv2 (coming soon) client methods (only HTTP POST and JSON request body are used in the v2 API)
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>pathwaycommons.cpath</groupId>
<artifactId>cpath-client</artifactId>
<version>10.0.1-SNAPSHOT</version>
<version>10.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>cpath2 client</name>
Expand Down Expand Up @@ -47,12 +47,12 @@
<dependency>
<groupId>org.biopax.paxtools</groupId>
<artifactId>paxtools-core</artifactId>
<version>5.3.0-SNAPSHOT</version>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.2.RELEASE</version>
<version>5.3.31</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand All @@ -63,12 +63,12 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>5.1.2.RELEASE</version>
<version>5.3.31</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.3</version>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -83,9 +83,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
<configuration>
<release>8</release>
<release>11</release>
</configuration>
</plugin>
<plugin>
Expand Down
25 changes: 10 additions & 15 deletions src/main/java/cpath/client/CPathClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CPathClient

// one can set the JVM property: -DcPath2Url="http://some_URL"
public static final String JVM_PROPERTY_ENDPOINT_URL = "cPath2Url";
public static final String DEFAULT_ENDPOINT_URL = "http://www.pathwaycommons.org/pc2/";
public static final String DEFAULT_ENDPOINT_URL = "https://www.pathwaycommons.org/pc2/";

private RestTemplate restTemplate;
private String endPointURL; //official external public cpath2 web service url
Expand Down Expand Up @@ -63,19 +63,19 @@ public static CPathClient newInstance() {
*/
public static CPathClient newInstance(String url) {
CPathClient client = new CPathClient();
// create a new REST template
client.restTemplate = new RestTemplate();
// create a new REST template
client.restTemplate = new RestTemplate();
// add custom cPath2 XML message converter as the first one (accepts 'application/xml' content type)
// because one of existing/default msg converters, XML root element based jaxb2, does not work for ServiceResponce types...
client.restTemplate.getMessageConverters().add(0, new ServiceResponseHttpMessageConverter());
// add BioPAX http message converter
// (SimpleIOHandler is not thread-safe; so we cannot share the thread-safe restTemplate)
client.restTemplate.getMessageConverters().add(1, new BioPAXHttpMessageConverter(new SimpleIOHandler()));
// set the cpath2 server URL (or default one or from the java option)
// (SimpleIOHandler is not thread-safe; so we cannot share the thread-safe restTemplate)
client.restTemplate.getMessageConverters().add(1, new BioPAXHttpMessageConverter(new SimpleIOHandler()));
// set the cpath2 server URL (or default one or from the java option)
if(url == null || url.isEmpty())
client.endPointURL = System.getProperty(JVM_PROPERTY_ENDPOINT_URL, DEFAULT_ENDPOINT_URL);
else
client.endPointURL = url;
client.endPointURL = System.getProperty(JVM_PROPERTY_ENDPOINT_URL, DEFAULT_ENDPOINT_URL);
else
client.endPointURL = url;

return client;
}
Expand All @@ -101,19 +101,14 @@ public <T> T post(String requestPath, MultiValueMap<String, String> requestParam

try {
return restTemplate.postForObject(url, requestParams, responseType);
// } catch (UnknownHttpStatusCodeException e) {
// if (e.getRawStatusCode() == 460) {
// return null; //empty result
// } else
// throw new CPathException(url + " and " + requestParams, e);
} catch (RestClientException e) {
throw new CPathException(url + " and " + requestParams, e);
}
}


/**
* Sends a HTTP GET request to the cpath2 server.
* Sends an HTTP GET request to the cPath2 server.
*
* Note: using {@link #post(String, MultiValueMap, Class)} is the preferred
* and more reliable method, especially with complex queries that use URIs or
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cpath/client/query/CPathTraverseQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class CPathTraverseQuery extends BaseCPathQuery<TraverseResponse> i
* @return the request
*/
protected MultiValueMap<String, String> getRequestParams() {
MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>();
MultiValueMap<String, String> request = new LinkedMultiValueMap<>();
if(source == null || source.length == 0)
throw new IllegalArgumentException("Required 'source' (URIs) parameter cannot be null or empty.");
request.put(CmdArgs.uri.name(), Arrays.asList(source));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@
import static org.junit.Assert.*;

/**
* INFO: when "cPath2Url" Java property is not set,
* (e.g., -DcPath2Url="http://localhost:8080/pc2/")
* the default cpath2 endpoint URL is {@link CPathClient#DEFAULT_ENDPOINT_URL}
* So, it is possible that the default (official) service still provides
* an older cpath2 API than this PC2 client expects.
* Take care.
* INFO: when "cPath2Url" Java property is not set (e.g., -DcPath2Url="http://localhost:8080/"),
* the default cpath2 endpoint URL is {@link CPathClient#DEFAULT_ENDPOINT_URL}.
* Run with JVM opts: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED
*/
@Ignore //these tests depend on the data, thus disabled by default (not for daily builds)
public class CPathClientTest {
public class CPathClientIT {

static CPathClient client;

static {
// client = CPathClient.newInstance("http://www.pathwaycommons.org/pc2/");
client = CPathClient.newInstance("http://beta.pathwaycommons.org/pc2/");
client.setName("CPathClientTest");
client = CPathClient.newInstance(null); //use the URL from -DcPath2Url=<url> JVM option or the default PC2 URL
client.setName("CPathClientIT");
}

final String testBioSourceUri = "http://identifiers.org/taxonomy/9606";
Expand All @@ -40,26 +36,22 @@ public class CPathClientTest {
@Test
public final void testBiopaxMediaType() {
String biopaxContentType = "application/vnd.biopax.rdf+xml";
// MimeTypeUtils.parseMimeType("application/vnd.biopax.rdf+xml");
MediaType mediaType = MediaType.parseMediaType(biopaxContentType);
assertNotNull(mediaType);
assertEquals(biopaxContentType, mediaType.toString());
}

@Test
public final void testConnectionEtc() throws CPathException {

String endPointURL = client.getEndPointURL();
System.out.println("cpath2 instance: " + endPointURL
+ " (actual location: " + client.getActualEndPointURL() + ")");
System.out.println("cpath2 instance: " + endPointURL + " (actual location: " + client.getActualEndPointURL() + ")");

String res = client.post("help/types", null, String.class);
assertTrue(res.contains("BioSource"));
res = client.get("help/types", null, String.class);
assertTrue(res.contains("BioSource"));
}


@Test
public final void testGetTopPathways() throws CPathException {
SearchResponse result = null;
Expand All @@ -71,13 +63,11 @@ public final void testGetTopPathways() throws CPathException {
result = null;
try {
result = client.createTopPathwaysQuery().datasourceFilter(new String[]{"foo"}).result();
} catch (CPathException e) {
}
// since pc9 beta; it sends "empty" data result...
} catch (CPathException e) {}
// since pc9 beta; it sends "empty" data result...
assertTrue(result == null || result.isEmpty());
}


@Test
public final void testTraverse() {
// must get a result w/o problems
Expand All @@ -104,7 +94,7 @@ public final void testTraverse() {
.propertyPath("Named/name")
.sources(new String[]{"bla-bla"})
.result();
//it does not anymore sends error response; it returns "empty" result
//it does not anymore send error response; it returns "empty" result
// fail("must throw CPathException now, for all error responses: 460, 452, 500...");
} catch (CPathException e) {
}
Expand Down Expand Up @@ -134,7 +124,6 @@ public final void testTraverse() {
assertFalse(resp.isEmpty());
}


@Test
public final void testSearch() {
ServiceResponse resp = null;
Expand Down Expand Up @@ -165,7 +154,6 @@ public final void testSearch() {
assertFalse(((SearchResponse) resp).getSearchHit().isEmpty());
}


@Test //this test is even more dependent on the data there
public final void testGetByUri() throws CPathException {
String id = "BRCA2";
Expand All @@ -189,7 +177,6 @@ public final void testGetByUri() throws CPathException {
assertTrue(res.contains("<sbgn"));
}


//@Ignore
@Test
public final void testPathsBetweenQuery() throws CPathException {
Expand All @@ -200,7 +187,6 @@ public final void testPathsBetweenQuery() throws CPathException {
.result();

System.out.println("model.getObjects(.size()) = " + model.getObjects().size());

SimpleIOHandler h = new SimpleIOHandler();

try {
Expand All @@ -210,7 +196,6 @@ public final void testPathsBetweenQuery() throws CPathException {
}
}


@Test //this test id data-dependent
public final void testGetPathwayByUri() throws CPathException {
Model m = client.createGetQuery()
Expand Down

0 comments on commit 31f1c60

Please sign in to comment.