diff --git a/commons/src/main/java/lcsb/mapviewer/common/geometry/ColorParser.java b/commons/src/main/java/lcsb/mapviewer/common/geometry/ColorParser.java index f76dce4edb7f08ab22821bdf6633a1e4a7bff89a..f78e460818ca7672354874b712036e714d35a789 100644 --- a/commons/src/main/java/lcsb/mapviewer/common/geometry/ColorParser.java +++ b/commons/src/main/java/lcsb/mapviewer/common/geometry/ColorParser.java @@ -1,6 +1,8 @@ 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; + } } diff --git a/frontend-js/src/main/js/Functions.js b/frontend-js/src/main/js/Functions.js index de976d6f3778f44c0acde57220c832bea03b711a..c2594abb1575f2dc79df84ec36093fc7b7c2b701 100644 --- a/frontend-js/src/main/js/Functions.js +++ b/frontend-js/src/main/js/Functions.js @@ -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; 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 0c2c7a6ea47a6108c58a00903ded58abedae174d..ec6bb96897cb4a0c4b6f3a8223ea59bc6be51813 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 @@ -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"); } diff --git a/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutAliasViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutAliasViewFactory.java index e42bc74452ab802039cdd8f87ac09afeb0eff40f..c08811bee4ad4a6f7c1f75b4fd60143f0e862d03 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutAliasViewFactory.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutAliasViewFactory.java @@ -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) { diff --git a/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutAliasView.java b/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutAliasView.java index bf8008175a72d11552548b7fc551cbeb968cf229..f4f8d5a612377b1428936b3d377afa5d1e692486 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutAliasView.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutAliasView.java @@ -1,6 +1,6 @@ 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; } diff --git a/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutAliasViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutAliasViewFactory.java index 0f37f3a0afe17a79edab2d9858bb2aed061e0d71..910a1b5a474907361138f8dbb12f91f18c58cc61 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutAliasViewFactory.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutAliasViewFactory.java @@ -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; }