diff --git a/frontend-js/src/main/js/ServerConnector.js b/frontend-js/src/main/js/ServerConnector.js index 3ff7d7b652efe21ab982898d1d40ffa2bf7f1031..e93a5625b17d5f0548e5c73f34277a9338a56680 100644 --- a/frontend-js/src/main/js/ServerConnector.js +++ b/frontend-js/src/main/js/ServerConnector.js @@ -381,7 +381,13 @@ ServerConnector.getOverlayElementsUrl = function(queryParams, filterParams) { }; -ServerConnector.getFullOverlayElementUrl = function(params, token) { +ServerConnector.getFullOverlayElementUrl = function(queryParams, filterParams) { + + return this.getApiUrl({ + url : this.getAliasesUrl(queryParams) + queryParams.id + "/", + params : filterParams, + }); + return this.getApiUrl({ type : "overlay", method : "getOverlayElement", @@ -426,11 +432,16 @@ ServerConnector.columnsToString = function(columns) { return columns; }; -ServerConnector.getModelsUrl = function(params) { - var modelId = this.getIdOrAsterisk(params.modelId); +ServerConnector.getModelsUrl = function(queryParams) { + var modelId = this.getIdOrAsterisk(queryParams.modelId); + var overlayId = queryParams.overlayId; + var url = this.getProjectsUrl(queryParams); + if (overlayId !== undefined) { + url = this.getOverlayByIdUrl(queryParams); + } return this.getApiUrl({ - url : this.getProjectsUrl(params) + "models/" + modelId + "/", + url : url + "models/" + modelId + "/", }); }; @@ -846,12 +857,19 @@ ServerConnector.getFullOverlayElement = function(params) { var self = this; var token = null; + var queryParams = { + overlayId : params.overlay.getId(), + modelId : params.element.getModelId(), + id : params.element.getId(), + } + var filterParams = {}; + return self.getToken().then(function(result) { - token = result; + filterParams.token = result; return self.getProjectId(params.projectId); }).then(function(result) { - params.projectId = result; - return self.readFile(self.getFullOverlayElementUrl(params, token)); + queryParams.projectId = result; + return self.readFile(self.getFullOverlayElementUrl(queryParams, filterParams)); }).then(function(content) { var element = JSON.parse(content); var result = null; diff --git a/frontend-js/testFiles/apiCalls/overlay/getOverlayElement/elementId=329163&elementType=ALIAS&modelId=15781&overlayId=18076&projectId=sample&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/projects/sample/overlays/18076/models/15781/bioEntities/elements/329163/token=MOCK_TOKEN_ID& similarity index 100% rename from frontend-js/testFiles/apiCalls/overlay/getOverlayElement/elementId=329163&elementType=ALIAS&modelId=15781&overlayId=18076&projectId=sample&token=MOCK_TOKEN_ID& rename to frontend-js/testFiles/apiCalls/projects/sample/overlays/18076/models/15781/bioEntities/elements/329163/token=MOCK_TOKEN_ID& diff --git a/frontend-js/testFiles/apiCalls/overlay/getOverlayElement/elementId=329163&elementType=ALIAS&modelId=15781&overlayId=18077&projectId=sample&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/projects/sample/overlays/18077/models/15781/bioEntities/elements/329163/token=MOCK_TOKEN_ID& similarity index 100% rename from frontend-js/testFiles/apiCalls/overlay/getOverlayElement/elementId=329163&elementType=ALIAS&modelId=15781&overlayId=18077&projectId=sample&token=MOCK_TOKEN_ID& rename to frontend-js/testFiles/apiCalls/projects/sample/overlays/18077/models/15781/bioEntities/elements/329163/token=MOCK_TOKEN_ID& diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayController.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayController.java index a40438e46cec76de5649c4e86c10f999fb5681a1..8196f53e14f688ae1438aef11980cc1bf326c097 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayController.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayController.java @@ -44,17 +44,44 @@ public class OverlayController extends BaseController { return overlayController.getOverlayById(token, projectId, overlayId); } - @RequestMapping(value = "/projects/{projectId}/overlays/{overlayId}/bioEntities/", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE }) - public List<Map<String, Object>> getOverlayElements( - @RequestParam(value = "token") String token, + @RequestMapping(value = "/projects/{projectId}/overlays/{overlayId}/bioEntities/", method = { RequestMethod.GET }, + produces = { MediaType.APPLICATION_JSON_VALUE }) + public List<Map<String, Object>> getOverlayElements(// + @RequestParam(value = "token") String token, // @PathVariable(value = "projectId") String projectId, // @PathVariable(value = "overlayId") String overlayId, - @RequestParam(value = "columns", defaultValue = "") String columns - ) + @RequestParam(value = "columns", defaultValue = "") String columns) throws SecurityException, QueryException { return overlayController.getOverlayElements(token, projectId, Integer.valueOf(overlayId), columns); } + @RequestMapping(value = "/projects/{projectId}/overlays/{overlayId}/models/{modelId}/bioEntities/reactions/{reactionId}/", method = { RequestMethod.GET }, + produces = { MediaType.APPLICATION_JSON_VALUE }) + public Map<String, Object> getFullReaction(// + @RequestParam(value = "token") String token, // + @PathVariable(value = "projectId") String projectId, // + @PathVariable(value = "modelId") String modelId, // + @PathVariable(value = "overlayId") String overlayId, // + @PathVariable(value = "reactionId") String reactionId, // + @RequestParam(value = "columns", defaultValue = "") String columns // + ) throws SecurityException, QueryException { + return overlayController + .getOverlayElement(token, projectId, Integer.valueOf(modelId), Integer.valueOf(overlayId), Integer.valueOf(reactionId), "REACTION", columns); + } + @RequestMapping(value = "/projects/{projectId}/overlays/{overlayId}/models/{modelId}/bioEntities/elements/{elementId}/", method = { RequestMethod.GET }, + produces = { MediaType.APPLICATION_JSON_VALUE }) + public Map<String, Object> getFullSpecies(// + @RequestParam(value = "token") String token, // + @PathVariable(value = "projectId") String projectId, // + @PathVariable(value = "modelId") String modelId, // + @PathVariable(value = "overlayId") String overlayId, // + @PathVariable(value = "elementId") String reactionId, // + @RequestParam(value = "columns", defaultValue = "") String columns // + ) throws SecurityException, QueryException { + return overlayController + .getOverlayElement(token, projectId, Integer.valueOf(modelId), Integer.valueOf(overlayId), Integer.valueOf(reactionId), "ALIAS", columns); + } + @RequestMapping(value = "/overlay/getOverlayTypes", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE }) public List<Map<String, Object>> getOverlayTypes(@RequestParam(value = "token") String token) throws SecurityException, QueryException { return overlayController.getOverlayTypes(token); @@ -97,15 +124,6 @@ public class OverlayController extends BaseController { .body(file.getFileContent()); } - @RequestMapping(value = "/overlay/getOverlayElement", method = { RequestMethod.GET, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE }) - public Map<String, Object> getFullElement(@RequestParam(value = "token") String token, @RequestParam(value = "projectId") String projectId, - @RequestParam(value = "modelId") String modelId, @RequestParam(value = "overlayId") String overlayId, - @RequestParam(value = "elementId") String elementId, @RequestParam(value = "elementType") String elementType, - @RequestParam(value = "columns", defaultValue = "") String columns) throws SecurityException, QueryException { - return overlayController - .getOverlayElement(token, projectId, Integer.valueOf(modelId), Integer.valueOf(overlayId), Integer.valueOf(elementId), elementType, columns); - } - /** * @return the overlayController * @see #overlayController diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java index bf6a0040511c3e7b0528a538214bf0085e079f8c..aef38648ff446f6437d2ffd5d703cc5794ab6c37 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java @@ -29,6 +29,7 @@ import lcsb.mapviewer.services.interfaces.IModelService; import lcsb.mapviewer.services.interfaces.IUserService; import lcsb.mapviewer.services.search.data.ElementIdentifier.ElementIdentifierType; import lcsb.mapviewer.services.search.layout.FullLayoutAliasView; +import lcsb.mapviewer.services.search.layout.FullLayoutReactionView; import lcsb.mapviewer.services.search.layout.LightLayoutAliasView; import lcsb.mapviewer.services.search.layout.LightLayoutReactionView; import lcsb.mapviewer.services.utils.data.ColorSchemaType; @@ -288,6 +289,11 @@ public class OverlayRestImpl extends BaseRestImpl { result.put("type", ElementIdentifierType.ALIAS); result.put("overlayContent", layoutAliasView); return result; + } else if (ElementIdentifierType.REACTION.getJsName().equals(elementType)) { + FullLayoutReactionView layoutAliasView = layoutService.getFullReactionForLayout(model, elementId, overlayId, authenticationToken); + result.put("type", ElementIdentifierType.REACTION); + result.put("overlayContent", layoutAliasView); + return result; } else { throw new QueryException("Unknown element type: " + elementType); } diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java index 08d1314773be8b3f220302fdf91f2ed7b0044e9f..5ebe9bb4cf4984cb40b050b18240ad02a4009c1e 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java @@ -60,6 +60,8 @@ import lcsb.mapviewer.services.interfaces.ILogService.LogParams; import lcsb.mapviewer.services.interfaces.IUserService; import lcsb.mapviewer.services.search.layout.FullLayoutAliasView; import lcsb.mapviewer.services.search.layout.FullLayoutAliasViewFactory; +import lcsb.mapviewer.services.search.layout.FullLayoutReactionView; +import lcsb.mapviewer.services.search.layout.FullLayoutReactionViewFactory; import lcsb.mapviewer.services.search.layout.LightLayoutAliasView; import lcsb.mapviewer.services.search.layout.LightLayoutAliasViewFactory; import lcsb.mapviewer.services.search.layout.LightLayoutReactionView; @@ -1075,4 +1077,30 @@ public class LayoutService implements ILayoutService { throw new InvalidStateException(e); } } + + @Override + public FullLayoutReactionView getFullReactionForLayout(Model model, Integer id, int layoutId, AuthenticationToken token) throws SecurityException { + try { + ColorSchemaReader reader = new ColorSchemaReader(); + Collection<ColorSchema> schemas; + schemas = reader.readColorSchema(getInputDataForLayout(layoutId, token)); + // colors here are not important + ColorModelCommand command = new ColorModelCommand(model, schemas, new ColorExtractor(Color.BLACK, Color.BLACK)); + FullLayoutReactionViewFactory factory = new FullLayoutReactionViewFactory(); + + for (Map.Entry<Object, ColorSchema> entry : command.getModifiedElements().entrySet()) { + if (entry.getKey() instanceof Reaction) { + Reaction alias = (Reaction) entry.getKey(); + if (id.equals(alias.getId())) { + return factory.create(new Pair<Reaction, ColorSchema>(alias, entry.getValue())); + } + } + } + return null; + } catch (InvalidColorSchemaException e) { + throw new InvalidStateException(e); + } catch (IOException e) { + throw new InvalidStateException(e); + } + } } diff --git a/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java b/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java index f5a1b1ca8c20d253922b6659f76035cddc590bd5..207b7d3d29b4881451eb48bf3f5761e548da75b9 100644 --- a/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java +++ b/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java @@ -16,6 +16,7 @@ import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.services.SecurityException; import lcsb.mapviewer.services.search.layout.FullLayoutAliasView; +import lcsb.mapviewer.services.search.layout.FullLayoutReactionView; import lcsb.mapviewer.services.search.layout.LightLayoutAliasView; import lcsb.mapviewer.services.search.layout.LightLayoutReactionView; import lcsb.mapviewer.services.utils.EmailSender; @@ -502,6 +503,8 @@ public interface ILayoutService { throws SecurityException; FullLayoutAliasView getFullAliasForLayout(Model model, Integer id, int layoutId, AuthenticationToken token) throws SecurityException; + + FullLayoutReactionView getFullReactionForLayout(Model model, Integer id, int layoutId, AuthenticationToken token) throws SecurityException; /** * Returns {@link EmailSender} used by the service. diff --git a/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutReactionView.java b/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutReactionView.java new file mode 100644 index 0000000000000000000000000000000000000000..126b8493872e024db5b495721ead6b687423e119 --- /dev/null +++ b/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutReactionView.java @@ -0,0 +1,15 @@ +package lcsb.mapviewer.services.search.layout; + +import lcsb.mapviewer.model.map.reaction.Reaction; + +public class FullLayoutReactionView extends LightLayoutReactionView { + + public FullLayoutReactionView(Reaction reaction) { + super(reaction); + } + + /** + * + */ + private static final long serialVersionUID = 1L; +} diff --git a/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutReactionViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutReactionViewFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..de40e6e11aef70a289ca1b9a97baea9ccbe008ed --- /dev/null +++ b/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutReactionViewFactory.java @@ -0,0 +1,39 @@ +package lcsb.mapviewer.services.search.layout; + +import org.apache.log4j.Logger; + +import com.google.gson.Gson; + +import lcsb.mapviewer.common.Pair; +import lcsb.mapviewer.model.map.layout.ColorSchema; +import lcsb.mapviewer.model.map.reaction.Reaction; +import lcsb.mapviewer.services.search.ElementViewFactory; + +/** + * Factory class for {@link LightLayoutReactionView} class. + * + * @author Piotr Gawron + * + */ +public class FullLayoutReactionViewFactory extends ElementViewFactory<Pair<Reaction, ColorSchema>, FullLayoutReactionView> { + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(FullLayoutReactionViewFactory.class); + + @Override + public FullLayoutReactionView create(Pair<Reaction, ColorSchema> pair) { + FullLayoutReactionView result = new FullLayoutReactionView(pair.getLeft()); + result.setColor(pair.getRight().getColor()); + result.setValue(pair.getRight().getValue()); + result.setWidth(pair.getRight().getLineWidth()); + result.setReverse(pair.getRight().getReverseReaction()); + return result; + } + + @Override + public String createGson(FullLayoutReactionView object) { + return new Gson().toJson(object); + } +}