Skip to content

Commit

Permalink
Merge pull request #59 from julesjacobsen/json-deserialise
Browse files Browse the repository at this point in the history
Json deserialise
  • Loading branch information
balhoff authored Feb 26, 2020
2 parents b5eb537 + a38ef83 commit f56ec14
Show file tree
Hide file tree
Showing 20 changed files with 260 additions and 152 deletions.
26 changes: 10 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.geneontology</groupId>
<artifactId>obographs</artifactId>
<version>0.2.0</version>
<version>0.2.1</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>Reference implementation for Obo Graphs</description>
Expand Down Expand Up @@ -168,6 +168,15 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<doclet>ch.raffael.doclets.pegdown.PegdownDoclet</doclet>
<docletArtifact>
<groupId>ch.raffael.pegdown-doclet</groupId>
<artifactId>pegdown-doclet</artifactId>
<version>1.1</version>
</docletArtifact>
<useStandardDocletOptions>true</useStandardDocletOptions>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -177,21 +186,6 @@
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<configuration>
<doclet>ch.raffael.doclets.pegdown.PegdownDoclet</doclet>
<docletArtifact>
<groupId>ch.raffael.pegdown-doclet</groupId>
<artifactId>pegdown-doclet</artifactId>
<version>1.1</version>
</docletArtifact>
<useStandardDocletOptions>true</useStandardDocletOptions>
</configuration>
</plugin>

</plugins>
</build>

Expand Down
17 changes: 8 additions & 9 deletions src/main/java/org/geneontology/obographs/io/OgJsonReader.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package org.geneontology.obographs.io;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.geneontology.obographs.model.GraphDocument;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import org.geneontology.obographs.model.Graph;

import com.fasterxml.jackson.databind.ObjectMapper;

public class OgJsonReader {

public static Graph readFile(String fileName) throws IOException {
public static GraphDocument readFile(String fileName) throws IOException {
return readFile(new File(fileName));
}

public static Graph readFile(File file) throws IOException {
public static GraphDocument readFile(File file) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readValue(file, Graph.class);
return objectMapper.readValue(file, GraphDocument.class);
}

public static Graph readInputStream(InputStream stream) throws IOException {
public static GraphDocument readInputStream(InputStream stream) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readValue(stream, Graph.class);
return objectMapper.readValue(stream, GraphDocument.class);
}

}
14 changes: 13 additions & 1 deletion src/main/java/org/geneontology/obographs/model/Edge.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.geneontology.obographs.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

/**
* An edge connects two nodes via a predicate
*
* @author cjm
*
*/
@JsonDeserialize(builder = Edge.Builder.class)
public class Edge implements NodeOrEdge {

private Edge(Builder builder) {
Expand Down Expand Up @@ -48,7 +51,15 @@ public String getObj() {
return obj;
}


@Override
public String toString() {
return "Edge{" +
"sub='" + sub + '\'' +
", pred='" + pred + '\'' +
", obj='" + obj + '\'' +
", meta=" + meta +
'}';
}

/**
* @return the meta
Expand Down Expand Up @@ -90,6 +101,7 @@ public Builder meta(Meta meta) {
return this;
}

@JsonCreator
public Edge build() {
return new Edge(this);
}
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/org/geneontology/obographs/model/Graph.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.geneontology.obographs.model;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.geneontology.obographs.model.axiom.DomainRangeAxiom;
import org.geneontology.obographs.model.axiom.EquivalentNodesSet;
import org.geneontology.obographs.model.axiom.LogicalDefinitionAxiom;
import org.geneontology.obographs.model.axiom.PropertyChainAxiom;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;

/**
* A graph object holds a collection of nodes and edges
Expand All @@ -33,6 +34,7 @@
* @author cjm
*
*/
@JsonDeserialize(builder = Graph.Builder.class)
public class Graph {

private Graph(Builder builder) {
Expand Down Expand Up @@ -139,6 +141,20 @@ public List<PropertyChainAxiom> getPropertyChainAxioms() {
}


@Override
public String toString() {
return "Graph{" +
"nodes=" + nodes +
", edges=" + edges +
", id='" + id + '\'' +
", lbl='" + lbl + '\'' +
", meta=" + meta +
", equivalentNodesSets=" + equivalentNodesSets +
", logicalDefinitionAxioms=" + logicalDefinitionAxioms +
", domainRangeAxioms=" + domainRangeAxioms +
", propertyChainAxioms=" + propertyChainAxioms +
'}';
}

public static class Builder {

Expand Down Expand Up @@ -202,6 +218,7 @@ public Builder domainRangeAxioms(List<DomainRangeAxiom> domainRangeAxioms) {
return this;
}

@JsonCreator
public Graph build() {
return new Graph(this);
}
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/org/geneontology/obographs/model/GraphDocument.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.geneontology.obographs.model;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import java.util.List;

/**
* Holds a collection of graphs, plus document-level metadata
Expand All @@ -23,6 +25,7 @@
* @author cjm
*
*/
@JsonDeserialize(builder = GraphDocument.Builder.class)
public class GraphDocument {

private GraphDocument(Builder builder) {
Expand Down Expand Up @@ -61,21 +64,24 @@ public Meta getMeta() {
}





@Override
public String toString() {
return "GraphDocument{" +
"graphs=" + graphs +
", meta=" + meta +
", context=" + context +
'}';
}

public static class Builder {

@JsonProperty
private Meta meta;
@JsonProperty
private List<Graph> graphs;
@JsonProperty
@JsonProperty("@context")
private Object context;



public Builder meta(Meta meta) {
this.meta = meta;
return this;
Expand All @@ -89,6 +95,7 @@ public Builder context(Object context) {
return this;
}

@JsonCreator
public GraphDocument build() {
return new GraphDocument(this);
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/geneontology/obographs/model/Meta.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.geneontology.obographs.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.geneontology.obographs.model.meta.*;

import java.util.ArrayList;
Expand All @@ -25,6 +27,7 @@
* @author cjm
*
*/
@JsonDeserialize(builder = Meta.Builder.class)
public class Meta {

private Meta(Builder builder) {
Expand Down Expand Up @@ -107,6 +110,20 @@ public Boolean getDeprecated() {
return deprecated;
}

@Override
public String toString() {
return "Meta{" +
"definition=" + definition +
", comments=" + comments +
", subsets=" + subsets +
", xrefs=" + xrefs +
", synonyms=" + synonyms +
", basicPropertyValues=" + basicPropertyValues +
", version='" + version + '\'' +
", deprecated=" + deprecated +
'}';
}

public static class Builder {

@JsonProperty
Expand Down Expand Up @@ -205,6 +222,7 @@ public Builder deprecated(Boolean deprecated) {
}


@JsonCreator
public Meta build() {
return new Meta(this);
}
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/org/geneontology/obographs/model/Node.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.geneontology.obographs.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

/**
* A graph node corresponds to a class, individual or property
Expand All @@ -19,6 +21,7 @@
* @author cjm
*
*/
@JsonDeserialize(builder = Node.Builder.class)
public class Node implements NodeOrEdge {

public enum RDFTYPES { CLASS, INDIVIDUAL, PROPERTY };
Expand Down Expand Up @@ -77,11 +80,21 @@ public Meta getMeta() {
return meta;
}

public static class Builder {
@Override
public String toString() {
return "Node{" +
"id='" + id + '\'' +
", label='" + label + '\'' +
", meta=" + meta +
", type=" + type +
'}';
}

public static class Builder {

@JsonProperty
private String id;
@JsonProperty
@JsonProperty("lbl")
private String label;
@JsonProperty
private Meta meta;
Expand All @@ -108,6 +121,7 @@ public Builder type(RDFTYPES type) {
return this;
}

@JsonCreator
public Node build() {
return new Node(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package org.geneontology.obographs.model.axiom;

import java.util.Set;

import org.geneontology.obographs.model.Meta;
import org.geneontology.obographs.model.axiom.EquivalentNodesSet.Builder;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.geneontology.obographs.model.Meta;

public abstract class AbstractAxiom implements Axiom {

Expand All @@ -31,7 +27,7 @@ public static class Builder {

@JsonProperty
private Meta meta;

public Builder meta(Meta meta) {
this.meta = meta;
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package org.geneontology.obographs.model.axiom;

import org.geneontology.obographs.model.Meta;
import org.geneontology.obographs.model.axiom.AbstractAxiom.Builder;

import com.fasterxml.jackson.annotation.JsonProperty;

public class AbstractExpression implements Expression {

protected AbstractExpression(Builder builder) {
}

public static class Builder {




}
}
Loading

0 comments on commit f56ec14

Please sign in to comment.