Skip to content

Commit

Permalink
Flatten Molecule so all fields are deserialized
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Oct 4, 2017
1 parent 283009b commit d2f228c
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 326 deletions.

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@
<generate>true</generate>
</sourceReferences>
<format>'v'yyyyMMddHHmm</format>
<!-- Uncomment to package with uncommited code
<!-- Uncomment to package with uncommited code-->
<jgit.dirtyWorkingTree>warning</jgit.dirtyWorkingTree>
-->
</configuration>
</plugin>
</plugins>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
package nl.esciencecenter.e3dchem.knime.molviewer.server.api;

import java.io.Serializable;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonInclude;

import io.swagger.annotations.ApiModelProperty;

public class Molecule extends AnonymousMolecule {
public Molecule(String data, String format) {
super(data, format);
}

public Molecule() {
super();
}

private static final long serialVersionUID = 8195661028979524114L;

@ApiModelProperty(required = true, value = "Identifier")
public String id;
@ApiModelProperty(required = true, value = "Label")
public String label;


@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Molecule other = (Molecule) obj;
return Objects.equals(this.id, other.id) && Objects.equals(this.label, other.label)
&& Objects.equals(this.format, other.format) && Objects.equals(this.data, other.data);
}

@Override
public int hashCode() {
return Objects.hash(id, label, format, data);
}
public class Molecule implements Serializable {
public Molecule(String data, String format) {
this.data = data;
this.format = format;
}

public Molecule() {
super();
}

private static final long serialVersionUID = 8195661028979524114L;

@ApiModelProperty(required = true, value = "Data format", allowableValues = "mol2, pdb, phar, sdf")
public String format = null;
@ApiModelProperty(required = true, value = "Data of molecule aka atoms/bonds in specified format")
public String data = null;
@ApiModelProperty(required = false, value = "Identifier")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public String id = null;
@ApiModelProperty(required = false, value = "Label")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public String label = null;

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Molecule other = (Molecule) obj;
return Objects.equals(this.id, other.id) && Objects.equals(this.label, other.label)
&& Objects.equals(this.format, other.format) && Objects.equals(this.data, other.data);
}

@Override
public int hashCode() {
return Objects.hash(id, label, format, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class PharmacophoreContainer implements Serializable {
@ApiModelProperty(required = true, value = "Label")
public String label;
@ApiModelProperty(required = true, value = "Pharmacophore")
public AnonymousMolecule pharmacophore;
public Molecule pharmacophore;
@ApiModelProperty(required = false, value = "Protein")
public AnonymousMolecule protein;
public Molecule protein;
@ApiModelProperty(required = false, value = "Ligand")
public AnonymousMolecule ligand;
public Molecule ligand;
@ApiModelProperty(required = false, value = "Transformation matrix")
public double[] transform = new double[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
import org.junit.Test;

import nl.esciencecenter.e3dchem.knime.molviewer.server.LigandsAndProteinsViewerServer;
import nl.esciencecenter.e3dchem.knime.molviewer.server.MolViewerServer;

public class MolViewerServerTest {
private MolViewerServer server;
private LigandsAndProteinsViewerServer server;

@Before
public void setUp() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package nl.esciencecenter.e3dchem.knime.molviewer.ligandsandproteins;

import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.core.StringContains.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
Expand All @@ -18,6 +21,7 @@
import org.knime.core.node.property.hilite.HiLiteHandler;

import nl.esciencecenter.e3dchem.knime.molviewer.server.LigandsAndProteinsViewerServer;
import nl.esciencecenter.e3dchem.knime.molviewer.server.api.Molecule;

public class LigandsAndProteinsViewerServerTest {
private LigandsAndProteinsViewerServer server;
Expand Down Expand Up @@ -75,4 +79,39 @@ public void testSwaggerJson() throws URISyntaxException, ClientProtocolException
assertThat(response, containsString("hilite"));
}

@Test
public void test_getLigands_optionalFilled() throws URISyntaxException, ClientProtocolException, IOException {
List<Molecule> ligands = new ArrayList<>(1);
Molecule ligand = new Molecule();
ligand.data = "Some data to render later";
ligand.id = "Row1";
ligand.label = "Label1";
ligand.format = "sdf";
ligands.add(ligand);
server.updateLigands(ligands);

URI uri = server.getBaseUri().resolve("/api/ligands");
String response = Request.Get(uri).execute().returnContent().asString();
assertThat(response, containsString("Row1"));
assertThat(response, containsString("Some data to render later"));
assertThat(response, containsString("Label1"));
assertThat(response, containsString("sdf"));
}

@Test
public void test_getLigands_requiredFilled() throws URISyntaxException, ClientProtocolException, IOException {
List<Molecule> ligands = new ArrayList<>(1);
Molecule ligand = new Molecule();
ligand.data = "Some data to render later";
ligand.format = "sdf";
ligands.add(ligand);
server.updateLigands(ligands);

URI uri = server.getBaseUri().resolve("/api/ligands");
String response = Request.Get(uri).execute().returnContent().asString();
assertThat(response, containsString("sdf"));
assertThat(response, containsString("Some data to render later"));
assertThat(response, not(containsString("id")));
assertThat(response, not(containsString("label")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.knime.core.node.CanceledExecutionException;
import org.knime.core.node.ExecutionMonitor;

import nl.esciencecenter.e3dchem.knime.molviewer.server.api.AnonymousMolecule;
import nl.esciencecenter.e3dchem.knime.molviewer.server.api.Molecule;
import nl.esciencecenter.e3dchem.knime.molviewer.server.api.PharmacophoreContainer;

public class PharmacophoresViewerModelTest {
Expand All @@ -25,9 +25,9 @@ public void testSaveAndLoad() throws IOException, CanceledExecutionException {
PharmacophoreContainer phar = new PharmacophoreContainer();
phar.id = "id1";
phar.label = "label1";
phar.pharmacophore = new AnonymousMolecule("...", "phar");
phar.ligand = new AnonymousMolecule("...", "sdf");
phar.protein = new AnonymousMolecule("...", "pdb");
phar.pharmacophore = new Molecule("...", "phar");
phar.ligand = new Molecule("...", "sdf");
phar.protein = new Molecule("...", "pdb");
node.getPharmacophores().add(phar);

ExecutionMonitor exec = null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,45 @@ public void testHashCodeDiff() {

assertNotEquals(mol.hashCode(), other.hashCode());
}

@Test
public void test_anonymousConstructor() {
Molecule mol = new Molecule();
assertNull(mol.format);
assertNull(mol.data);
}

@Test
public void test_constructor() {
Molecule mol = new Molecule("data", "format");
assertEquals("data", mol.data);
assertEquals("format", mol.format);
}

@Test
public void testEqualsNull_dataConstructor() {
Molecule mol = new Molecule("data", "format");

assertFalse(mol.equals(null));
}

@Test
public void testEqualsString() {
Molecule mol = new Molecule("data", "format");

assertFalse(mol.equals("no mol"));
}

@Test
public void testHashCode() {
Molecule mol = new Molecule("data", "format");
assertEquals(-673444332L, mol.hashCode());
}

@Test
public void testEqualsFilledProps_dataConstructor() {
Molecule mol = new Molecule("data1", "format1");
Molecule other = new Molecule("data1", "format1");
assertTrue(mol.equals(other));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public void testEqualsFilledProps_otherUnset() {
PharmacophoreContainer phar = new PharmacophoreContainer();
phar.id = "id1";
phar.label = "label1";
phar.pharmacophore = new AnonymousMolecule("...", "phar");
phar.ligand = new AnonymousMolecule("...", "sdf");
phar.protein = new AnonymousMolecule("...", "pdb");
phar.pharmacophore = new Molecule("...", "phar");
phar.ligand = new Molecule("...", "sdf");
phar.protein = new Molecule("...", "pdb");

PharmacophoreContainer other = new PharmacophoreContainer();
assertFalse(phar.equals(other));
Expand All @@ -38,16 +38,16 @@ public void testEqualsFilledProps_otherSameFill() {
PharmacophoreContainer phar = new PharmacophoreContainer();
phar.id = "id1";
phar.label = "label1";
phar.pharmacophore = new AnonymousMolecule("...", "phar");
phar.ligand = new AnonymousMolecule("...", "sdf");
phar.protein = new AnonymousMolecule("...", "pdb");
phar.pharmacophore = new Molecule("...", "phar");
phar.ligand = new Molecule("...", "sdf");
phar.protein = new Molecule("...", "pdb");

PharmacophoreContainer other = new PharmacophoreContainer();
other.id = "id1";
other.label = "label1";
other.pharmacophore = new AnonymousMolecule("...", "phar");
other.ligand = new AnonymousMolecule("...", "sdf");
other.protein = new AnonymousMolecule("...", "pdb");
other.pharmacophore = new Molecule("...", "phar");
other.ligand = new Molecule("...", "sdf");
other.protein = new Molecule("...", "pdb");
assertTrue(phar.equals(other));
}

Expand Down

0 comments on commit d2f228c

Please sign in to comment.