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

new api call for get overlay detail data about element

parent 556a67e8
No related branches found
No related tags found
1 merge request!11Resolve "Rest API should follow google guidlines"
This commit is part of merge request !11. Comments created here will be created in the context of that merge request.
Showing
with 148 additions and 21 deletions
......@@ -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;
......
......@@ -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
......
......@@ -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);
}
......
......@@ -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);
}
}
}
......@@ -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.
......
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;
}
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);
}
}
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