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

rest api for getting publication list

parent d9e53e71
No related branches found
No related tags found
1 merge request!5Frontend refactor
......@@ -75,6 +75,12 @@ public class ProjectController extends BaseController {
return projectController.getElementsByQuery(projectId, token, query, maxElements, perfectMatch);
}
@RequestMapping(value = "/getPublications", method = { RequestMethod.GET, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
public Map<String, Object> getPublications(@RequestParam(value = "projectId") String projectId, @RequestParam(value = "token") String token,
@RequestParam(value = "start", defaultValue = "0") String start, @RequestParam(value = "length", defaultValue = "10") Integer length) throws QueryException, SecurityException {
return projectController.getPublications(projectId, token, start, length);
}
@RequestMapping(value = "/getProjectSource", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<byte[]> getOverlaySource(@RequestParam(value = "token") String token, @RequestParam(value = "projectId") String projectId)
throws SecurityException, QueryException {
......
......@@ -8,6 +8,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
......@@ -20,6 +22,7 @@ import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.cache.FileEntry;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.AnnotatedObject;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.OverviewImage;
......@@ -114,35 +117,48 @@ public class ProjectRestImpl {
}
result.setMap(new ModelMetaData(model));
Set<MiriamData> publications = new HashSet<>();
List<ModelData> models = new ArrayList<>();
for (ModelSubmodelConnection connection : model.getSubmodels()) {
models.add(connection.getSubmodel());
}
models.add(model);
for (ModelData modelData : models) {
for (Element element : modelData.getElements()) {
for (MiriamData md : element.getMiriamData()) {
if (md.getDataType().equals(MiriamType.PUBMED)) {
publications.add(md);
result.setPublicationCount(getPublications(model).size());
}
return result;
}
private SortedMap<MiriamData, List<AnnotatedObject>> getPublications(ModelData model) {
SortedMap<MiriamData, List<AnnotatedObject>> publications = new TreeMap<>();
List<ModelData> models = new ArrayList<>();
for (ModelSubmodelConnection connection : model.getSubmodels()) {
models.add(connection.getSubmodel());
}
models.add(model);
for (ModelData modelData : models) {
for (Element element : modelData.getElements()) {
for (MiriamData md : element.getMiriamData()) {
if (md.getDataType().equals(MiriamType.PUBMED)) {
List<AnnotatedObject> list = publications.get(md);
if (list == null) {
list = new ArrayList<>();
publications.put(md, list);
}
list.add(element);
}
}
for (Reaction reaction : modelData.getReactions()) {
for (MiriamData md : reaction.getMiriamData()) {
if (md.getDataType().equals(MiriamType.PUBMED)) {
publications.add(md);
}
for (Reaction reaction : modelData.getReactions()) {
for (MiriamData md : reaction.getMiriamData()) {
if (md.getDataType().equals(MiriamType.PUBMED)) {
List<AnnotatedObject> list = publications.get(md);
if (list == null) {
list = new ArrayList<>();
publications.put(md, list);
}
list.add(reaction);
}
}
}
result.setPublicationCount(publications.size());
}
}
return result;
return publications;
}
/**
......@@ -463,4 +479,48 @@ public class ProjectRestImpl {
return entry;
}
public Map<String, Object> getPublications(String projectId, String token, String startString, Integer length) throws SecurityException, QueryException {
AuthenticationToken authenticationToken = userService.getToken(token);
Model model = modelService.getLastModelByProjectId(projectId, authenticationToken);
if (model == null) {
throw new QueryException("Project with given id doesn't exist");
}
Integer start = Math.max(0, Integer.valueOf(startString));
List<Map<String, Object>> resultList = new ArrayList<>();
SortedMap<MiriamData, List<AnnotatedObject>> publications = getPublications(model.getModelData());
int index = 0;
Set<String> columns = new HashSet<>();
columns.add("id");
columns.add("type");
columns.add("modelid");
for (Map.Entry<MiriamData, List<AnnotatedObject>> entry : publications.entrySet()) {
if (index >= start && index < start + length) {
List<Object> elements = new ArrayList<>();
for (AnnotatedObject object: entry.getValue()) {
if (object instanceof Element) {
elements.add(preparedElement((Element) object, columns));
} else if (object instanceof Reaction) {
elements.add(preparedReaction((Reaction) object, columns));
}
}
Map<String, Object> row = new HashMap<>();
row.put("elements", elements);
row.put("publication", annotationViewFactory.create(entry.getKey()));
resultList.add(row);
}
index++;
}
Map<String, Object> result = new HashMap<>();
result.put("data", resultList);
result.put("totalSize", publications.size());
result.put("start", start);
result.put("length", resultList.size());
return result;
}
}
......@@ -112,4 +112,29 @@ public class ProjectRestImplTest extends RestTestFunctions {
return _projectRestImpl;
}
@Test
public void testPublications() throws Exception {
try {
ProjectRestImpl projectRest = createMockProjectRest("testFiles/model/sample.xml");
Map<String, Object> result= projectRest.getPublications("sample", token.getId(),"0", 20);
assertEquals(1, result.get("totalSize"));
assertEquals(0, result.get("start"));
assertEquals(1, ((List<?>)result.get("data")).size());
result= projectRest.getPublications("sample", token.getId(),"1", 20);
assertEquals(1, result.get("totalSize"));
assertEquals(1, result.get("start"));
assertEquals(0, ((List<?>)result.get("data")).size());
result= projectRest.getPublications("sample", token.getId(),"0", 00);
assertEquals(1, result.get("totalSize"));
assertEquals(0, result.get("start"));
assertEquals(0, ((List<?>)result.get("data")).size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
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