Skip to content
Snippets Groups Projects
Commit 86d82b99 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

serialization issue when chemical didn't have casId defined

parent a121588d
No related branches found
No related tags found
1 merge request!92Chemical serialization issue
...@@ -75,8 +75,8 @@ public abstract class BaseRestImpl { ...@@ -75,8 +75,8 @@ public abstract class BaseRestImpl {
}; };
protected Map<String, Object> createAnnotation(MiriamData annotation) { protected Map<String, Object> createAnnotation(MiriamData annotation) {
Map<String, Object> result = new HashMap<>();
if (annotation != null && annotation.getDataType() != null) { if (annotation != null && annotation.getDataType() != null) {
Map<String, Object> result = new HashMap<>();
if (annotation.getDataType().getUris().size() > 0) { if (annotation.getDataType().getUris().size() > 0) {
try { try {
result.put("link", miriamConnector.getUrlString(annotation)); result.put("link", miriamConnector.getUrlString(annotation));
...@@ -95,8 +95,10 @@ public abstract class BaseRestImpl { ...@@ -95,8 +95,10 @@ public abstract class BaseRestImpl {
result.put("type", annotation.getDataType().name()); result.put("type", annotation.getDataType().name());
result.put("resource", annotation.getResource()); result.put("resource", annotation.getResource());
result.put("id", annotation.getId()); result.put("id", annotation.getId());
return result;
} else {
throw new InvalidArgumentException("invalid miriam data: " + annotation);
} }
return result;
}; };
protected Map<String, Object> createAnnotation(AnnotationView annotation) { protected Map<String, Object> createAnnotation(AnnotationView annotation) {
......
...@@ -120,7 +120,7 @@ public class ChemicalRestImpl extends BaseRestImpl { ...@@ -120,7 +120,7 @@ public class ChemicalRestImpl extends BaseRestImpl {
this.modelService = modelService; this.modelService = modelService;
} }
private Map<String, Object> prepareChemical(Chemical chemical, Set<String> columnsSet, List<Model> models) { protected Map<String, Object> prepareChemical(Chemical chemical, Set<String> columnsSet, List<Model> models) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
String description = "Mesh term not available"; String description = "Mesh term not available";
...@@ -144,14 +144,18 @@ public class ChemicalRestImpl extends BaseRestImpl { ...@@ -144,14 +144,18 @@ public class ChemicalRestImpl extends BaseRestImpl {
} else if (column.equals("references")) { } else if (column.equals("references")) {
List<Map<String, Object>> references = new ArrayList<>(); List<Map<String, Object>> references = new ArrayList<>();
references.add(createAnnotation(chemical.getChemicalId())); references.add(createAnnotation(chemical.getChemicalId()));
references.add(createAnnotation(chemical.getCasID())); if (chemical.getCasID() != null) {
references.add(createAnnotation(chemical.getCasID()));
}
value = references; value = references;
} else if (column.equals("directevidencereferences")) { } else if (column.equals("directevidencereferences")) {
value = createAnnotations(chemical.getDirectEvidencePublication()); value = createAnnotations(chemical.getDirectEvidencePublication());
} else if (column.equals("description")) { } else if (column.equals("description")) {
value = description; value = description;
} else if (column.equals("directevidence")) { } else if (column.equals("directevidence")) {
value = chemical.getDirectEvidence().getValue(); if (chemical.getDirectEvidence() != null) {
value = chemical.getDirectEvidence().getValue();
}
} else if (column.equals("synonyms")) { } else if (column.equals("synonyms")) {
value = synonyms; value = synonyms;
} else if (column.equals("targets")) { } else if (column.equals("targets")) {
...@@ -164,7 +168,7 @@ public class ChemicalRestImpl extends BaseRestImpl { ...@@ -164,7 +168,7 @@ public class ChemicalRestImpl extends BaseRestImpl {
return result; return result;
} }
private Set<String> createChemicalColumnSet(String columns) { protected Set<String> createChemicalColumnSet(String columns) {
Set<String> columnsSet = new HashSet<>(); Set<String> columnsSet = new HashSet<>();
if (columns.equals("")) { if (columns.equals("")) {
columnsSet.add("name"); columnsSet.add("name");
......
package lcsb.mapviewer.api.projects.chemicals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import java.util.ArrayList;
import java.util.Map;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.annotation.data.Chemical;
import lcsb.mapviewer.annotation.data.ChemicalDirectEvidence;
import lcsb.mapviewer.annotation.data.ChemicalDirectEvidenceTest;
import lcsb.mapviewer.api.RestTestFunctions;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.services.interfaces.IModelService;
public class ChemicalRestImplTest extends RestTestFunctions {
Logger logger = Logger.getLogger(ChemicalRestImplTest.class);
@Autowired
private ChemicalRestImpl _drugRestImpl;
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testPrepareChemical() throws Exception {
try {
Chemical chemical = new Chemical();
chemical.setChemicalId(new MiriamData(MiriamType.MESH_2012, "D010300"));
Map<String, Object> result = _drugRestImpl.prepareChemical(chemical, _drugRestImpl.createChemicalColumnSet(""), new ArrayList<>());
assertNotNull(result);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
protected ChemicalRestImpl createMockChemicalRest(String string) throws Exception {
Model model = super.getModelForFile(string, true);
IModelService mockModelService = Mockito.mock(IModelService.class);
Mockito.when(mockModelService.getLastModelByProjectId(anyString(), any())).thenReturn(model);
_drugRestImpl.setModelService(mockModelService);
return _drugRestImpl;
}
}
...@@ -40,7 +40,7 @@ public class DrugRestImplTest extends RestTestFunctions { ...@@ -40,7 +40,7 @@ public class DrugRestImplTest extends RestTestFunctions {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testGetModelAsImage() throws Exception { public void testGetDrugsByQuery() throws Exception {
try { try {
DrugRestImpl drugRestImpl = createMockProjectRest("testFiles/model/sample.xml"); DrugRestImpl drugRestImpl = createMockProjectRest("testFiles/model/sample.xml");
Map<String, Object> result = drugRestImpl.getDrugsByQuery(token.getId(), "sample", "", "nadh").get(0); Map<String, Object> result = drugRestImpl.getDrugsByQuery(token.getId(), "sample", "", "nadh").get(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment