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

color of element is returned as a map with properties

parent 2e7c47d9
No related branches found
No related tags found
1 merge request!107Resolve "data overlays with defined color are visualized improperly"
package lcsb.mapviewer.common.geometry;
import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
......@@ -56,4 +58,17 @@ public class ColorParser {
Integer.valueOf(string.substring(COLOR_SUBSTRING_START_BLUE, COLOR_STRING_LENGTH), HEX_BASE));
}
}
/**
* Converts color into list of atributes.
*
* @param color color to convert
* @return map with list of color attributes
*/
public Map<String, Object> colorToMap(Color color) {
Map<String, Object> result = new HashMap<>();
result.put("alpha", color.getAlpha());
result.put("rgb", color.getRGB());
return result;
}
}
......@@ -170,7 +170,7 @@ Functions.overlayToColor = function(elementOverlay) {
if (elementOverlay === null || elementOverlay === undefined) {
return Promise.reject("elementOverlay cannot be null!");
} else if (elementOverlay.color !== undefined && elementOverlay.color !== null) {
return Promise.resolve(self.intToColorString(elementOverlay.color.value));
return Promise.resolve(self.intToColorString(elementOverlay.color.rgb));
} else {
var ratio = 0;
var promiseColor = null;
......
......@@ -47,11 +47,6 @@ public class OverlayRestImpl extends BaseRestImpl {
*/
private Logger logger = Logger.getLogger(OverlayRestImpl.class);
@Autowired
private IUserService userService;
@Autowired
private IModelService modelService;
@Autowired
private ILayoutService layoutService;
......@@ -60,31 +55,14 @@ public class OverlayRestImpl extends BaseRestImpl {
private LayoutDao layoutDao;
public List<LayoutView> getOverlayList(String token, String projectId) throws SecurityException, QueryException {
AuthenticationToken authenticationToken = userService.getToken(token);
Model model = modelService.getLastModelByProjectId(projectId, authenticationToken);
AuthenticationToken authenticationToken = getUserService().getToken(token);
Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken);
if (model == null) {
throw new QueryException("Project with given id doesn't exist");
}
return layoutService.getCustomLayouts(model, token);
}
/**
* @return the userService
* @see #userService
*/
public IUserService getUserService() {
return userService;
}
/**
* @param userService
* the userService to set
* @see #userService
*/
public void setUserService(IUserService userService) {
this.userService = userService;
}
/**
* @return the layoutService
* @see #layoutService
......@@ -102,28 +80,11 @@ public class OverlayRestImpl extends BaseRestImpl {
this.layoutService = layoutService;
}
/**
* @return the modelService
* @see #modelService
*/
public IModelService getModelService() {
return modelService;
}
/**
* @param modelService
* the modelService to set
* @see #modelService
*/
public void setModelService(IModelService modelService) {
this.modelService = modelService;
}
public List<Map<String, Object>> getOverlayElements(String token, String projectId, int overlayId, String columns) throws QueryException, SecurityException {
List<Map<String, Object>> result = new ArrayList<>();
AuthenticationToken authenticationToken = userService.getToken(token);
AuthenticationToken authenticationToken = getUserService().getToken(token);
Model model = modelService.getLastModelByProjectId(projectId, authenticationToken);
Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken);
if (model == null) {
throw new QueryException("Project with given id doesn't exist");
}
......@@ -146,8 +107,8 @@ public class OverlayRestImpl extends BaseRestImpl {
}
public LayoutView getOverlayById(String token, String projectId, String overlayId) throws SecurityException, QueryException {
AuthenticationToken authenticationToken = userService.getToken(token);
Model model = modelService.getLastModelByProjectId(projectId, authenticationToken);
AuthenticationToken authenticationToken = getUserService().getToken(token);
Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken);
if (model == null) {
throw new QueryException("Project with given id doesn't exist");
}
......@@ -155,8 +116,8 @@ public class OverlayRestImpl extends BaseRestImpl {
}
public FileEntry getOverlaySource(String token, String projectId, String overlayId) throws SecurityException, QueryException {
AuthenticationToken authenticationToken = userService.getToken(token);
Model model = modelService.getLastModelByProjectId(projectId, authenticationToken);
AuthenticationToken authenticationToken = getUserService().getToken(token);
Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken);
if (model == null) {
throw new QueryException("Project with given id doesn't exist");
}
......@@ -175,8 +136,8 @@ public class OverlayRestImpl extends BaseRestImpl {
}
public LayoutView updateOverlay(String token, String projectId, String overlayId, Map<String, Object> overlayData) throws QueryException, SecurityException {
AuthenticationToken authenticationToken = userService.getToken(token);
Model model = modelService.getLastModelByProjectId(projectId, authenticationToken);
AuthenticationToken authenticationToken = getUserService().getToken(token);
Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken);
if (model == null) {
throw new QueryException("Project with given id doesn't exist");
}
......@@ -184,7 +145,7 @@ public class OverlayRestImpl extends BaseRestImpl {
throw new QueryException("overlay field cannot be undefined");
}
Project project = model.getProject();
boolean isAdmin = userService.userHasPrivilege(authenticationToken, PrivilegeType.LAYOUT_MANAGEMENT, project);
boolean isAdmin = getUserService().userHasPrivilege(authenticationToken, PrivilegeType.LAYOUT_MANAGEMENT, project);
try {
Integer id = Integer.valueOf(overlayId);
Layout layout = layoutService.getLayoutDataById(id, authenticationToken);
......@@ -208,8 +169,8 @@ public class OverlayRestImpl extends BaseRestImpl {
}
public Map<String, Object> removeOverlay(String token, String projectId, String overlayId) throws QueryException, SecurityException, IOException {
AuthenticationToken authenticationToken = userService.getToken(token);
Model model = modelService.getLastModelByProjectId(projectId, authenticationToken);
AuthenticationToken authenticationToken = getUserService().getToken(token);
Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken);
if (model == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist");
}
......@@ -249,12 +210,12 @@ public class OverlayRestImpl extends BaseRestImpl {
public LayoutView addOverlay(String token, String projectId, String name, String description, String content, String filename, String type)
throws SecurityException, QueryException, IOException {
AuthenticationToken authenticationToken = userService.getToken(token);
User user = userService.getUserByToken(token);
AuthenticationToken authenticationToken = getUserService().getToken(token);
User user = getUserService().getUserByToken(token);
if (Configuration.ANONYMOUS_LOGIN.equals(user.getLogin())) {
throw new SecurityException("You have no privileges to add overlay");
}
Model model = modelService.getLastModelByProjectId(projectId, authenticationToken);
Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken);
if (model == null) {
throw new QueryException("Project with given id doesn't exist");
}
......@@ -284,9 +245,9 @@ public class OverlayRestImpl extends BaseRestImpl {
public Map<String, Object> getOverlayElement(String token, String projectId, Integer modelId, Integer overlayId, Integer elementId, String elementType,
String columns) throws QueryException, SecurityException {
AuthenticationToken authenticationToken = userService.getToken(token);
AuthenticationToken authenticationToken = getUserService().getToken(token);
Model topModel = modelService.getLastModelByProjectId(projectId, authenticationToken);
Model topModel = getModelService().getLastModelByProjectId(projectId, authenticationToken);
if (topModel == null) {
throw new QueryException("Project with given id doesn't exist");
}
......
......@@ -5,6 +5,7 @@ import org.apache.log4j.Logger;
import com.google.gson.Gson;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.geometry.ColorParser;
import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.layout.GeneVariationColorSchema;
import lcsb.mapviewer.model.map.species.Element;
......@@ -18,18 +19,26 @@ import lcsb.mapviewer.services.utils.data.ColorSchemaType;
*
*/
public class FullLayoutAliasViewFactory extends ElementViewFactory<Pair<Element, ColorSchema>, FullLayoutAliasView> {
/**
* Parser to map color into object that can be returned to client side.
*/
private ColorParser parser = new ColorParser();
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(FullLayoutAliasViewFactory.class);
private static Logger logger = Logger.getLogger(FullLayoutAliasViewFactory.class);
@Override
public FullLayoutAliasView create(Pair<Element, ColorSchema> pair) {
ColorSchema schema = pair.getRight();
FullLayoutAliasView result = new FullLayoutAliasView(pair.getLeft());
result.setColor(schema.getColor());
if (schema.getColor() != null) {
result.setColor(parser.colorToMap(schema.getColor()));
}
result.setValue(schema.getValue());
result.setDescription(schema.getDescription());
if (schema instanceof GeneVariationColorSchema) {
......
package lcsb.mapviewer.services.search.layout;
import java.awt.Color;
import java.util.Map;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.services.search.ElementView;
......@@ -18,17 +18,17 @@ public class LightLayoutAliasView extends ElementView {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* Value used to highlight {@link Element} in a a layout.
*/
private Double value;
private Double value;
/**
* Color used to highlight {@link Element} in a layout.
*/
private Color color;
private Map<String, Object> color;
/**
* Default constructor.
......@@ -68,7 +68,7 @@ public class LightLayoutAliasView extends ElementView {
* @return the color
* @see #color
*/
public Color getColor() {
public Map<String, Object> getColor() {
return color;
}
......@@ -77,7 +77,7 @@ public class LightLayoutAliasView extends ElementView {
* the color to set
* @see #color
*/
public void setColor(Color color) {
public void setColor(Map<String, Object> color) {
this.color = color;
}
......
......@@ -5,6 +5,7 @@ import org.apache.log4j.Logger;
import com.google.gson.Gson;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.geometry.ColorParser;
import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.services.search.ElementViewFactory;
......@@ -16,16 +17,25 @@ import lcsb.mapviewer.services.search.ElementViewFactory;
*
*/
public class LightLayoutAliasViewFactory extends ElementViewFactory<Pair<Element, ColorSchema>, LightLayoutAliasView> {
/**
* Parser to map color into object that can be returned to client side.
*/
private ColorParser parser = new ColorParser();
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(LightLayoutAliasViewFactory.class);
private static Logger logger = Logger.getLogger(LightLayoutAliasViewFactory.class);
@Override
public LightLayoutAliasView create(Pair<Element, ColorSchema> pair) {
LightLayoutAliasView result = new LightLayoutAliasView(pair.getLeft());
result.setColor(pair.getRight().getColor());
if (pair.getRight().getColor() != null) {
result.setColor(parser.colorToMap(pair.getRight().getColor()));
}
result.setValue(pair.getRight().getValue());
return result;
}
......
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