From ba1719328ff962fb74e2843b121e61cd273c13f1 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Wed, 26 Oct 2016 11:32:37 +0200 Subject: [PATCH] comments on submaps are centered correctly --- .../converter/graphics/ImageGenerators.java | 17 +-- .../mapviewer/services/view/CommentView.java | 12 +- .../services/view/CommentViewFactory.java | 17 ++- .../services/view/CommentViewFactoryTest.java | 130 +++++++++++------- 4 files changed, 110 insertions(+), 66 deletions(-) diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ImageGenerators.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ImageGenerators.java index 534c33e740..9498239a8b 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ImageGenerators.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ImageGenerators.java @@ -15,7 +15,6 @@ import lcsb.mapviewer.common.exception.InvalidStateException; import lcsb.mapviewer.converter.graphics.AbstractImageGenerator.Params; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelFullIndexed; -import lcsb.mapviewer.model.user.ConfigurationElementType; /** * This class is a util class containing information about all currently @@ -29,7 +28,7 @@ public class ImageGenerators { * Default class logger. */ @SuppressWarnings("unused") - private final Logger logger = Logger.getLogger(ImageGenerators.class); + private final Logger logger = Logger.getLogger(ImageGenerators.class); /** * List of {@link AbstractImageGenerator} classes available in the system. */ @@ -39,7 +38,7 @@ public class ImageGenerators { * List of all possible objects extending {@link AbstractImageGenerator} * interface that are available in the system. */ - private List<AbstractImageGenerator> generatorInstances = null; + private List<AbstractImageGenerator> generatorInstances = null; /** * Default constructor. @@ -51,17 +50,15 @@ public class ImageGenerators { AbstractImageGenerator.Params params = new AbstractImageGenerator.Params().// model(model).// width(1).// - minColor(Color.WHITE). - maxColor(Color.WHITE). - height(1); + minColor(Color.WHITE).maxColor(Color.WHITE).height(1); generatorInstances = new ArrayList<>(); generatorInstances.add(new PngImageGenerator(params)); generatorInstances.add(new PdfImageGenerator(params)); -// generatorInstances.add(new SvgImageGenerator(params)); -// generatorInstances.add(new JpgImageGenerator(params)); + // generatorInstances.add(new SvgImageGenerator(params)); + // generatorInstances.add(new JpgImageGenerator(params)); for (AbstractImageGenerator abstractImageGenerator : generatorInstances) { - availableGenerators.add(new Pair<String, Class<? extends AbstractImageGenerator>>(abstractImageGenerator.getFormatName(), abstractImageGenerator - .getClass())); + availableGenerators + .add(new Pair<String, Class<? extends AbstractImageGenerator>>(abstractImageGenerator.getFormatName(), abstractImageGenerator.getClass())); } } catch (DrawingException e) { diff --git a/service/src/main/java/lcsb/mapviewer/services/view/CommentView.java b/service/src/main/java/lcsb/mapviewer/services/view/CommentView.java index 43033fde72..0cffa23ff6 100644 --- a/service/src/main/java/lcsb/mapviewer/services/view/CommentView.java +++ b/service/src/main/java/lcsb/mapviewer/services/view/CommentView.java @@ -12,11 +12,11 @@ import lcsb.mapviewer.model.map.Comment; */ public class CommentView extends AbstractView<Comment> implements Serializable { - + /** * */ - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; /** * Author of the comment. @@ -63,7 +63,10 @@ public class CommentView extends AbstractView<Comment> implements Serializable { * details). */ private String zoom; - + + /** + * Submap on which comment was placed. + */ private String submap; /** @@ -279,7 +282,8 @@ public class CommentView extends AbstractView<Comment> implements Serializable { } /** - * @param submap the submap to set + * @param submap + * the submap to set * @see #submap */ public void setSubmap(String submap) { diff --git a/service/src/main/java/lcsb/mapviewer/services/view/CommentViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/view/CommentViewFactory.java index d5c1a44570..09b8318332 100644 --- a/service/src/main/java/lcsb/mapviewer/services/view/CommentViewFactory.java +++ b/service/src/main/java/lcsb/mapviewer/services/view/CommentViewFactory.java @@ -7,6 +7,7 @@ import org.apache.log4j.Logger; import com.google.gson.Gson; import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.model.map.Comment; import lcsb.mapviewer.model.map.model.Model; @@ -50,15 +51,22 @@ public class CommentViewFactory extends AbstractViewFactory<Comment, CommentView return result; } - result.setAuthor((comment.getName())); - result.setContent((comment.getContent())); - result.setEmail((comment.getEmail())); + result.setAuthor(comment.getName()); + result.setContent(comment.getContent()); + result.setEmail(comment.getEmail()); result.setPinned(comment.isPinned()); if (comment.isDeleted()) { result.setRemoved("YES (" + comment.getRemoveReason() + ")"); } else { result.setRemoved("NO"); } + if (comment.getSubmodelData() != null) { + result.setSubmap(comment.getSubmodelData().getId() + ""); + model = model.getSubmodelById(comment.getSubmodelData().getId()); + if (model == null) { + throw new InvalidArgumentException("Cannot find submodel with id: " + comment.getSubmodelData().getId()); + } + } String title = ""; Point2D coordinates = null; @@ -88,9 +96,6 @@ public class CommentViewFactory extends AbstractViewFactory<Comment, CommentView } } result.setTitle(title); - if (comment.getSubmodelData() != null) { - result.setSubmap(comment.getSubmodelData().getId() + ""); - } if (coordinates != null) { result.setxCoord(coordinates.getX()); result.setyCoord(coordinates.getY()); diff --git a/service/src/test/java/lcsb/mapviewer/services/view/CommentViewFactoryTest.java b/service/src/test/java/lcsb/mapviewer/services/view/CommentViewFactoryTest.java index e187e52775..13aeba6fe5 100644 --- a/service/src/test/java/lcsb/mapviewer/services/view/CommentViewFactoryTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/view/CommentViewFactoryTest.java @@ -1,46 +1,84 @@ -package lcsb.mapviewer.services.view; - -import static org.junit.Assert.assertNotNull; -import lcsb.mapviewer.services.ServiceTestFunctions; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; - -public class CommentViewFactoryTest extends ServiceTestFunctions{ - - @Autowired - CommentViewFactory commentViewFactory; - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testCreateEmpty() throws Exception { - try { - Object object = commentViewFactory.create(null); - assertNotNull(object); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - @Test - public void testCreateGson() throws Exception { - try { - CommentView object = commentViewFactory.create(null); - assertNotNull(commentViewFactory.createGson(object)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - -} +package lcsb.mapviewer.services.view; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import lcsb.mapviewer.model.map.Comment; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.model.ModelFullIndexed; +import lcsb.mapviewer.model.map.model.ModelSubmodelConnection; +import lcsb.mapviewer.model.map.model.SubmodelType; +import lcsb.mapviewer.model.map.species.GenericProtein; +import lcsb.mapviewer.model.map.species.Species; +import lcsb.mapviewer.services.ServiceTestFunctions; + +public class CommentViewFactoryTest extends ServiceTestFunctions { + + Logger logger = Logger.getLogger(CommentViewFactoryTest.class); + + @Autowired + CommentViewFactory commentViewFactory; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testCreateEmpty() throws Exception { + try { + Object object = commentViewFactory.create(null); + assertNotNull(object); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCreateGson() throws Exception { + try { + CommentView object = commentViewFactory.create(null); + assertNotNull(commentViewFactory.createGson(object)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCreateOnSubmap() throws Exception { + try { + Model model = new ModelFullIndexed(null); + Model submodel = new ModelFullIndexed(null); + submodel.setId(1); + Species species = new GenericProtein("id"); + species.setId(23); + species.setName("ProteinName"); + submodel.addElement(species); + + model.addSubmodelConnection(new ModelSubmodelConnection(submodel, SubmodelType.UNKNOWN)); + + Comment comment = new Comment(); + comment.setModel(model); + comment.setSubmodel(submodel); + comment.setTableName(species.getClass()); + comment.setTableId(species.getId()); + CommentView object = commentViewFactory.create(comment,model); + assertTrue(object.getTitle().contains(species.getName())); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} -- GitLab