Commit 0ed86847 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

types are serialized by jackson

parent 93508b07
...@@ -24,11 +24,11 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -24,11 +24,11 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import lcsb.mapviewer.api.BaseController; import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.api.SerializationUtils;
import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.cache.FileEntry; import lcsb.mapviewer.model.cache.FileEntry;
import lcsb.mapviewer.model.overlay.DataOverlay; import lcsb.mapviewer.model.overlay.DataOverlay;
import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.modelutils.serializer.model.map.ElementIdentifierType;
import lcsb.mapviewer.services.ObjectNotFoundException; import lcsb.mapviewer.services.ObjectNotFoundException;
import lcsb.mapviewer.services.QueryException; import lcsb.mapviewer.services.QueryException;
import lcsb.mapviewer.services.interfaces.IDataOverlayService; import lcsb.mapviewer.services.interfaces.IDataOverlayService;
...@@ -98,11 +98,12 @@ public class OverlayController extends BaseController { ...@@ -98,11 +98,12 @@ public class OverlayController extends BaseController {
@GetMapping(value = "/{overlayId}/models/{modelId}/bioEntities/") @GetMapping(value = "/{overlayId}/models/{modelId}/bioEntities/")
public List<Map<String, Object>> getOverlayElements( public List<Map<String, Object>> getOverlayElements(
@PathVariable(value = "projectId") String projectId, @PathVariable(value = "projectId") String projectId,
@PathVariable(value = "overlayId") String overlayId, @PathVariable(value = "overlayId") Integer overlayId,
@RequestParam(value = "columns", defaultValue = "") String columns) throws QueryException { @RequestParam(value = "columns", defaultValue = "") String columns) throws QueryException {
if (overlayId == null) {
return overlayRestImp.getOverlayElements(projectId, SerializationUtils.parseInteger(overlayId, "overlayId"), throw new QueryException("Invalid overlayId");
columns); }
return overlayRestImp.getOverlayElements(projectId, overlayId, columns);
} }
@PreAuthorize("hasAuthority('IS_ADMIN')" + @PreAuthorize("hasAuthority('IS_ADMIN')" +
...@@ -112,17 +113,17 @@ public class OverlayController extends BaseController { ...@@ -112,17 +113,17 @@ public class OverlayController extends BaseController {
@GetMapping(value = "/{overlayId}/models/{modelId}/bioEntities/reactions/{reactionId}/") @GetMapping(value = "/{overlayId}/models/{modelId}/bioEntities/reactions/{reactionId}/")
public List<Map<String, Object>> getFullReaction( public List<Map<String, Object>> getFullReaction(
@PathVariable(value = "projectId") String projectId, @PathVariable(value = "projectId") String projectId,
@PathVariable(value = "modelId") String modelId, @PathVariable(value = "modelId") Integer modelId,
@PathVariable(value = "overlayId") Integer overlayId, @PathVariable(value = "overlayId") Integer overlayId,
@PathVariable(value = "reactionId") String reactionId, @PathVariable(value = "reactionId") Integer reactionId,
@RequestParam(value = "columns", defaultValue = "") String columns) @RequestParam(value = "columns", defaultValue = "") String columns)
throws QueryException, NumberFormatException, ObjectNotFoundException { throws QueryException {
return overlayRestImp.getOverlayElement(projectId, return overlayRestImp.getOverlayElement(projectId,
SerializationUtils.parseInteger(modelId, "modelId"), modelId,
SerializationUtils.parseInteger(overlayId, "overlayId"), overlayId,
SerializationUtils.parseInteger(reactionId, "reactionId"), reactionId,
"REACTION", columns); ElementIdentifierType.REACTION, columns);
} }
@PreAuthorize("hasAuthority('IS_ADMIN')" + @PreAuthorize("hasAuthority('IS_ADMIN')" +
...@@ -132,16 +133,16 @@ public class OverlayController extends BaseController { ...@@ -132,16 +133,16 @@ public class OverlayController extends BaseController {
@GetMapping(value = "/{overlayId}/models/{modelId}/bioEntities/elements/{elementId}/") @GetMapping(value = "/{overlayId}/models/{modelId}/bioEntities/elements/{elementId}/")
public List<Map<String, Object>> getFullSpecies( public List<Map<String, Object>> getFullSpecies(
@PathVariable(value = "projectId") String projectId, @PathVariable(value = "projectId") String projectId,
@PathVariable(value = "modelId") String modelId, @PathVariable(value = "modelId") Integer modelId,
@PathVariable(value = "overlayId") Integer overlayId, @PathVariable(value = "overlayId") Integer overlayId,
@PathVariable(value = "elementId") String reactionId, @PathVariable(value = "elementId") Integer elementId,
@RequestParam(value = "columns", defaultValue = "") String columns) @RequestParam(value = "columns", defaultValue = "") String columns)
throws QueryException, NumberFormatException, ObjectNotFoundException { throws QueryException {
return overlayRestImp.getOverlayElement(projectId, return overlayRestImp.getOverlayElement(projectId,
SerializationUtils.parseInteger(modelId, "modelId"), modelId,
SerializationUtils.parseInteger(overlayId, "overlayId"), overlayId,
SerializationUtils.parseInteger(reactionId, "reactionId"), elementId,
"ALIAS", columns); ElementIdentifierType.ALIAS, columns);
} }
@PreAuthorize("hasAuthority('IS_ADMIN')" + @PreAuthorize("hasAuthority('IS_ADMIN')" +
......
...@@ -61,7 +61,7 @@ public class OverlayRestImpl extends BaseRestImpl { ...@@ -61,7 +61,7 @@ public class OverlayRestImpl extends BaseRestImpl {
this.dataOverlayService = dataOverlayService; this.dataOverlayService = dataOverlayService;
} }
public List<Map<String, Object>> getOverlayElements(String projectId, int overlayId, String columns) public List<Map<String, Object>> getOverlayElements(String projectId, Integer overlayId, String columns)
throws QueryException { throws QueryException {
String[] columnSet; String[] columnSet;
...@@ -72,8 +72,7 @@ public class OverlayRestImpl extends BaseRestImpl { ...@@ -72,8 +72,7 @@ public class OverlayRestImpl extends BaseRestImpl {
} }
List<Map<String, Object>> result = new ArrayList<>(); List<Map<String, Object>> result = new ArrayList<>();
List<Pair<Element, DataOverlayEntry>> speciesList = dataOverlayService.getElementsForDataOverlay(projectId, List<Pair<Element, DataOverlayEntry>> speciesList = dataOverlayService.getElementsForDataOverlay(projectId, overlayId);
overlayId);
for (Pair<Element, DataOverlayEntry> elementDataOverlay : speciesList) { for (Pair<Element, DataOverlayEntry> elementDataOverlay : speciesList) {
Map<String, Object> element = new TreeMap<>(); Map<String, Object> element = new TreeMap<>();
element.put("type", ElementIdentifierType.ALIAS); element.put("type", ElementIdentifierType.ALIAS);
...@@ -247,7 +246,7 @@ public class OverlayRestImpl extends BaseRestImpl { ...@@ -247,7 +246,7 @@ public class OverlayRestImpl extends BaseRestImpl {
} }
public List<Map<String, Object>> getOverlayElement(String projectId, Integer modelId, Integer overlayId, public List<Map<String, Object>> getOverlayElement(String projectId, Integer modelId, Integer overlayId,
Integer elementId, String elementType, String columns) throws QueryException { Integer elementId, ElementIdentifierType elementType, String columns) throws QueryException {
dataOverlayService.getDataOverlayById(projectId, overlayId); dataOverlayService.getDataOverlayById(projectId, overlayId);
String[] columnSet; String[] columnSet;
if (columns != null && !columns.trim().isEmpty()) { if (columns != null && !columns.trim().isEmpty()) {
...@@ -258,40 +257,44 @@ public class OverlayRestImpl extends BaseRestImpl { ...@@ -258,40 +257,44 @@ public class OverlayRestImpl extends BaseRestImpl {
"uniqueId" }; "uniqueId" };
} }
List<Map<String, Object>> result = new ArrayList<>(); List<Map<String, Object>> result = new ArrayList<>();
if (ElementIdentifierType.ALIAS.getJsName().equals(elementType)) { switch (elementType) {
List<Pair<Element, DataOverlayEntry>> elementDataOverlay = dataOverlayService case ALIAS: {
.getFullElementForDataOverlay( List<Pair<Element, DataOverlayEntry>> elementDataOverlay = dataOverlayService
projectId, .getFullElementForDataOverlay(
modelId, projectId,
elementId, modelId,
overlayId); elementId,
if (elementDataOverlay.size() == 0) { overlayId);
throw new ObjectNotFoundException("Element data cannot be found"); if (elementDataOverlay.size() == 0) {
} throw new ObjectNotFoundException("Element data cannot be found");
for (Pair<Element, DataOverlayEntry> pair : elementDataOverlay) { }
Map<String, Object> entry = new HashMap<>(); for (Pair<Element, DataOverlayEntry> pair : elementDataOverlay) {
entry.put("type", ElementIdentifierType.ALIAS); Map<String, Object> entry = new HashMap<>();
entry.put("overlayContent", overlayContentToMap(pair, columnSet)); entry.put("type", ElementIdentifierType.ALIAS);
result.add(entry); entry.put("overlayContent", overlayContentToMap(pair, columnSet));
result.add(entry);
}
return result;
} }
return result; case REACTION: {
} else if (ElementIdentifierType.REACTION.getJsName().equals(elementType)) { List<Pair<Reaction, DataOverlayEntry>> reactionDataOverlay = dataOverlayService
List<Pair<Reaction, DataOverlayEntry>> reactionDataOverlay = dataOverlayService .getFullReactionForDataOverlay(projectId,
.getFullReactionForDataOverlay(projectId, modelId,
modelId, elementId, overlayId);
elementId, overlayId); if (reactionDataOverlay.size() == 0) {
if (reactionDataOverlay.size() == 0) { throw new ObjectNotFoundException("Reaction data cannot be found");
throw new ObjectNotFoundException("Reaction data cannot be found"); }
for (Pair<Reaction, DataOverlayEntry> pair : reactionDataOverlay) {
Map<String, Object> entry = new HashMap<>();
entry.put("type", ElementIdentifierType.REACTION);
entry.put("overlayContent", overlayContentToMap(pair, columnSet));
result.add(entry);
}
return result;
} }
for (Pair<Reaction, DataOverlayEntry> pair : reactionDataOverlay) { default: {
Map<String, Object> entry = new HashMap<>(); throw new QueryException("Unknown element type: " + elementType);
entry.put("type", ElementIdentifierType.REACTION);
entry.put("overlayContent", overlayContentToMap(pair, columnSet));
result.add(entry);
} }
return result;
} else {
throw new QueryException("Unknown element type: " + elementType);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment