diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/alias/SpeciesAliasXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/alias/SpeciesAliasXmlParser.java index 60a9e523a44bd658d76b30de7ab3e6ee9c2f2408..29de42936083bc05aabc03ef9853ea2c56d9a1b5 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/alias/SpeciesAliasXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/alias/SpeciesAliasXmlParser.java @@ -4,6 +4,7 @@ import org.apache.log4j.Logger; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection; @@ -150,6 +151,8 @@ public class SpeciesAliasXmlParser extends AbstractAliasXmlParser<Species> { species.updateModelElementAfterLayoutAdded(result); return result; + } catch (InvalidArgumentException e) { + throw new InvalidXmlSchemaException(errorPrefix + e.getMessage(), e); } catch (NotImplementedException e) { throw new InvalidXmlSchemaException(errorPrefix + "Problem with creating species", e); } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXml.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXml.java index 93b36d3da15633ba9456a0ba187c5a2b79e05347..aaf6deac15abb02301c9d109aad3d4d678fa26ac 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXml.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXml.java @@ -156,8 +156,9 @@ public class ReactionToXml extends XmlParser { * @param reaction * reaction for which list is generated * @return xml node with list of modification + * @throws InconsistentModelException */ - private String getListOfModificationsXmlStringForReaction(Reaction reaction) { + private String getListOfModificationsXmlStringForReaction(Reaction reaction) throws InconsistentModelException { StringBuilder sb = new StringBuilder(); sb.append("<celldesigner:listOfModification>\n"); @@ -312,15 +313,16 @@ public class ReactionToXml extends XmlParser { } /** - * Creates xml node for given modifer. + * Creates xml node for given modifier. * * @param modifier - * modifier to be transaformed + * modifier to be transformed * @param gate * operator to which modifier is connected (if any) - * @return xml node for given modifer + * @return xml node for given modifier + * @throws InconsistentModelException */ - private String getModifierXmlString(Modifier modifier, NodeOperator gate) { + private String getModifierXmlString(Modifier modifier, NodeOperator gate) throws InconsistentModelException { StringBuilder sb = new StringBuilder(); ModifierTypeUtils modifierTypeUtils = new ModifierTypeUtils(); sb.append("<celldesigner:modification "); @@ -340,21 +342,26 @@ public class ReactionToXml extends XmlParser { line.setStartPoint(start); } - List<Point2D> points = lineTransformation.getPointsFromLine(line); - if (points.size() > 0) { + try { + List<Point2D> points = lineTransformation.getPointsFromLine(line); + if (points.size() > 0) { - boolean first = true; - sb.append(" editPoints=\""); + boolean first = true; + sb.append(" editPoints=\""); - for (Point2D point : points) { - if (first) { - first = false; - } else { - sb.append(" "); + for (Point2D point : points) { + if (first) { + first = false; + } else { + sb.append(" "); + } + sb.append(point.getX() + "," + point.getY()); } - sb.append(point.getX() + "," + point.getY()); + sb.append("\""); } - sb.append("\""); + } catch (InvalidArgumentException e) { + throw new InconsistentModelException(new ElementUtils().getElementTag(modifier) + "Problem with exporting line", + e); } sb.append(">\n"); @@ -479,8 +486,9 @@ public class ReactionToXml extends XmlParser { * @param reaction * reaction to be processed * @return xml node representing annotation part + * @throws InconsistentModelException */ - private String getAnnotationXmlStringForReaction(Reaction reaction) { + private String getAnnotationXmlStringForReaction(Reaction reaction) throws InconsistentModelException { ReactionLineData rdl = ReactionLineData.getByReactionType(reaction.getClass()); if (rdl == null) { throw new InvalidArgumentException("Unknown reaction type: " + reaction.getClass()); diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParserTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParserTest.java index 2cefdb5ec198f1385754e9538e8bde15ea3a2ca7..08d31257d193971461c3bade4575d7180ad34a9d 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParserTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerXmlParserTest.java @@ -135,7 +135,7 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions { CellDesignerXmlParser parser = new CellDesignerXmlParser(); parser.createModel(new ConverterParams().filename("testFiles/invalid/sample10.xml")); fail("Exceptin expected"); - } catch (InvalidArgumentException e) { + } catch (InvalidInputDataExecption e) { assertTrue(e.getMessage().contains("No type information for modification")); } catch (Exception e) { e.printStackTrace(); diff --git a/debian/create-debian-pkg.sh b/debian/create-debian-pkg.sh index f56f8a9e045a0f40be2f448058b2861d94eec53d..6eef85de2294e01a8bf6b202ae9e1c94ab17395f 100755 --- a/debian/create-debian-pkg.sh +++ b/debian/create-debian-pkg.sh @@ -15,9 +15,6 @@ dbschemadiff=management_scripts/db_schema_and_diff.sh #Where source file of the debian package should be placed SRC_DIR=debian/src -#where the documentation files are stored -DOC_DIR=doc - #File that should be deployed on tomcat TOMCAT_FILE=web/target/web-1.0.war @@ -42,7 +39,7 @@ mkdir $SRC_DIR cp $TOMCAT_FILE $SRC_DIR/minerva.war #copy manual documentation -cp $DOC_DIR/description.txt $SRC_DIR/minerva.txt +cp debian/description.txt $SRC_DIR/minerva.txt gzip -n $SRC_DIR/minerva.txt #copy configuration of logrotate diff --git a/debian/description.txt b/debian/description.txt new file mode 100644 index 0000000000000000000000000000000000000000..786ee1cd6ad012b1cbf42a3416065e159d911af0 --- /dev/null +++ b/debian/description.txt @@ -0,0 +1,2 @@ +MINERVA (Molecular Interaction NEtwoRk VisuAlization) platform is a standalone webserver for visualization, exploration and management of molecular networks encoded in SBGN-compliant format. After installation, the resource is used and managed via a web browser, under the default address 'http://localhost:8080/minerva/'. You can configure your Tomcat server later to change the address. + diff --git a/model-command/pom.xml b/model-command/pom.xml index df81c883631b7962fb23df500f944a35a3fd1328..a6d6b9166e5e5d8ba19f8ceef4098a0756356950 100644 --- a/model-command/pom.xml +++ b/model-command/pom.xml @@ -33,6 +33,14 @@ <version>${log4j.version}</version> </dependency> + <!-- mockito used for testing --> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>${mockito.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> @@ -40,6 +48,7 @@ <scope>test</scope> </dependency> + </dependencies> </project> \ No newline at end of file diff --git a/model-command/src/main/java/lcsb/mapviewer/commands/MoveElementsCommand.java b/model-command/src/main/java/lcsb/mapviewer/commands/MoveElementsCommand.java index ab6002da40becb5143b83e4a654e27efbc8f82af..db732b843dea35067f42c58c7af2b1b98688064c 100644 --- a/model-command/src/main/java/lcsb/mapviewer/commands/MoveElementsCommand.java +++ b/model-command/src/main/java/lcsb/mapviewer/commands/MoveElementsCommand.java @@ -2,12 +2,16 @@ package lcsb.mapviewer.commands; import java.awt.geom.Point2D; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.log4j.Logger; + import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidStateException; +import lcsb.mapviewer.model.map.BioEntity; import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.reaction.Modifier; @@ -17,8 +21,8 @@ import lcsb.mapviewer.model.map.reaction.Reactant; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.ReactionNode; import lcsb.mapviewer.model.map.species.Element; - -import org.apache.log4j.Logger; +import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.SpeciesWithModificationResidue; /** * Command which moves elements in model by dx, dy coordinates. @@ -28,154 +32,159 @@ import org.apache.log4j.Logger; */ public class MoveElementsCommand extends ModelCommand { - /** - * Default class logger. - */ - private final Logger logger = Logger.getLogger(MoveElementsCommand.class); - - /** - * Delta x. - */ - private double dx; - - /** - * Delta y. - */ - private double dy; - - /** - * List of objects to move. - */ - private List<Object> objectsToMove = new ArrayList<>(); - - /** - * Default constructor. - * - * @param model - * model to move - * @param elements - * elements that should be moved - * @param dx - * delta x - * @param dy - * delat y - */ - public MoveElementsCommand(Model model, List<Object> elements, double dx, double dy) { - super(model); - this.dx = dx; - this.dy = dy; - for (Object object : elements) { - if (object instanceof Element) { - if (((Element) object).getModel() != model) { - throw new InvalidArgumentException("Object doesnt belong to specified model: " + object); - } - } else if (object instanceof Reaction) { - if (((Reaction) object).getModel() != model) { - throw new InvalidArgumentException("Object doesnt belong to specified model: " + object); - } - } else { - throw new InvalidArgumentException("Cannot move element: " + object); - } - } - objectsToMove = elements; - } - - @Override - protected void undoImplementation() { - dx = -dx; - dy = -dy; - executeImplementation(); - dx = -dx; - dy = -dy; - setStatus(ModelCommandStatus.UNDONE); - } - - @Override - protected void redoImplementation() { - executeImplementation(); - setStatus(ModelCommandStatus.EXECUTED); - } - - @Override - protected void executeImplementation() { - Set<Element> aliases = new HashSet<>(); - - for (Object object : objectsToMove) { - if (object instanceof Element) { - Element alias = (Element) object; - - includeInAffectedRegion(alias); - - alias.setX(alias.getX() + dx); - alias.setY(alias.getY() + dy); - if (alias instanceof Compartment) { - ((Compartment) alias) - .setNamePoint(((Compartment) alias).getNamePoint().getX() + dx, ((Compartment) alias).getNamePoint().getY() + dy); - } - - includeInAffectedRegion(alias); - - aliases.add(alias); - } else if (object instanceof Reaction) { - Reaction reaction = (Reaction) object; - for (Reactant node : reaction.getReactants()) { - for (int i = 1; i < node.getLine().getPoints().size(); i++) { - Point2D point = node.getLine().getPoints().get(i); - logger.debug("Moving point: " + point); - point.setLocation(point.getX() + dx, point.getY() + dy); - } - } - for (Product node : reaction.getProducts()) { - for (int i = 0; i < node.getLine().getPoints().size() - 1; i++) { - Point2D point = node.getLine().getPoints().get(i); - point.setLocation(point.getX() + dx, point.getY() + dy); - } - } - for (Modifier node : reaction.getModifiers()) { - for (int i = 1; i < node.getLine().getPoints().size(); i++) { - Point2D point = node.getLine().getPoints().get(i); - point.setLocation(point.getX() + dx, point.getY() + dy); - } - } - for (NodeOperator node : reaction.getOperators()) { - for (int i = 0; i < node.getLine().getPoints().size(); i++) { - Point2D point = node.getLine().getPoints().get(i); - point.setLocation(point.getX() + dx, point.getY() + dy); - } - } - includeInAffectedRegion(reaction); - } else { - throw new InvalidStateException("Unknown class type: " + object); - } - } - if (aliases.size() > 0) { - // TODO this must be improved, we cannot do full search on every move - for (Reaction reaction : getModel().getReactions()) { - for (ReactionNode node : reaction.getReactionNodes()) { - if (aliases.contains(node.getElement())) { - if (node instanceof Reactant) { - Point2D point = node.getLine().getBeginPoint(); - point.setLocation(point.getX() + dx, point.getY() + dy); - - // we don't have to include point that we change as it's already - // on the border of the element - includeInAffectedRegion(node.getLine().getPoints().get(1)); - } else if (node instanceof Modifier) { - Point2D point = node.getLine().getBeginPoint(); - point.setLocation(point.getX() + dx, point.getY() + dy); - // we don't have to include point that we change as it's already - // on the border of the element - includeInAffectedRegion(node.getLine().getPoints().get(1)); - } else if (node instanceof Product) { - Point2D point = node.getLine().getEndPoint(); - point.setLocation(point.getX() + dx, point.getY() + dy); - // we don't have to include point that we change as it's already - // on the border of the element - includeInAffectedRegion(node.getLine().getPoints().get(node.getLine().getPoints().size() - 1)); - } - } - } - } - } - } + /** + * Default class logger. + */ + private final Logger logger = Logger.getLogger(MoveElementsCommand.class); + + /** + * Delta x. + */ + private double dx; + + /** + * Delta y. + */ + private double dy; + + /** + * List of objects to move. + */ + private List<Object> objectsToMove = new ArrayList<>(); + + /** + * Default constructor. + * + * @param model + * model to move + * @param elements + * elements that should be moved + * @param dx + * delta x + * @param dy + * delta y + */ + public MoveElementsCommand(Model model, Collection<? extends BioEntity> elements, double dx, double dy) { + super(model); + this.dx = dx; + this.dy = dy; + for (Object object : elements) { + if (object instanceof Element) { + if (((Element) object).getModel() != model) { + throw new InvalidArgumentException("Object doesnt belong to specified model: " + object); + } + } else if (object instanceof Reaction) { + if (((Reaction) object).getModel() != model) { + throw new InvalidArgumentException("Object doesnt belong to specified model: " + object); + } + } else { + throw new InvalidArgumentException("Cannot move element: " + object); + } + } + objectsToMove.addAll(elements); + } + + @Override + protected void undoImplementation() { + dx = -dx; + dy = -dy; + executeImplementation(); + dx = -dx; + dy = -dy; + setStatus(ModelCommandStatus.UNDONE); + } + + @Override + protected void redoImplementation() { + executeImplementation(); + setStatus(ModelCommandStatus.EXECUTED); + } + + @Override + protected void executeImplementation() { + Set<Element> aliases = new HashSet<>(); + + for (Object object : objectsToMove) { + if (object instanceof Element) { + Element alias = (Element) object; + + includeInAffectedRegion(alias); + + alias.setX(alias.getX() + dx); + alias.setY(alias.getY() + dy); + if (alias instanceof Compartment) { + ((Compartment) alias) + .setNamePoint(((Compartment) alias).getNamePoint().getX() + dx, + ((Compartment) alias).getNamePoint().getY() + dy); + } + if (alias instanceof SpeciesWithModificationResidue) { + for (ModificationResidue mr : ((SpeciesWithModificationResidue) alias).getModificationResidues()) { + Point2D position = mr.getPosition(); + position.setLocation(position.getX() + dx, position.getY() + dy); + } + } + includeInAffectedRegion(alias); + + aliases.add(alias); + } else if (object instanceof Reaction) { + Reaction reaction = (Reaction) object; + for (Reactant node : reaction.getReactants()) { + for (int i = 1; i < node.getLine().getPoints().size(); i++) { + Point2D point = node.getLine().getPoints().get(i); + node.getLine().getPoints().set(i, new Point2D.Double(point.getX() + dx, point.getY() + dy)); + } + } + for (Product node : reaction.getProducts()) { + for (int i = 0; i < node.getLine().getPoints().size() - 1; i++) { + Point2D point = node.getLine().getPoints().get(i); + node.getLine().getPoints().set(i, new Point2D.Double(point.getX() + dx, point.getY() + dy)); + } + } + for (Modifier node : reaction.getModifiers()) { + for (int i = 1; i < node.getLine().getPoints().size(); i++) { + Point2D point = node.getLine().getPoints().get(i); + node.getLine().getPoints().set(i, new Point2D.Double(point.getX() + dx, point.getY() + dy)); + } + } + for (NodeOperator node : reaction.getOperators()) { + for (int i = 0; i < node.getLine().getPoints().size(); i++) { + Point2D point = node.getLine().getPoints().get(i); + node.getLine().getPoints().set(i, new Point2D.Double(point.getX() + dx, point.getY() + dy)); + } + } + includeInAffectedRegion(reaction); + } else { + throw new InvalidStateException("Unknown class type: " + object); + } + } + if (aliases.size() > 0) { + // TODO this must be improved, we cannot do full search on every move + for (Reaction reaction : getModel().getReactions()) { + for (ReactionNode node : reaction.getReactionNodes()) { + if (aliases.contains(node.getElement())) { + if (node instanceof Reactant) { + Point2D point = node.getLine().getBeginPoint(); + point.setLocation(point.getX() + dx, point.getY() + dy); + + // we don't have to include point that we change as it's already + // on the border of the element + includeInAffectedRegion(node.getLine().getPoints().get(1)); + } else if (node instanceof Modifier) { + Point2D point = node.getLine().getBeginPoint(); + point.setLocation(point.getX() + dx, point.getY() + dy); + // we don't have to include point that we change as it's already + // on the border of the element + includeInAffectedRegion(node.getLine().getPoints().get(1)); + } else if (node instanceof Product) { + Point2D point = node.getLine().getEndPoint(); + point.setLocation(point.getX() + dx, point.getY() + dy); + // we don't have to include point that we change as it's already + // on the border of the element + includeInAffectedRegion(node.getLine().getPoints().get(node.getLine().getPoints().size() - 1)); + } + } + } + } + } + } } diff --git a/model-command/src/test/java/lcsb/mapviewer/commands/MoveElementsCommandTest.java b/model-command/src/test/java/lcsb/mapviewer/commands/MoveElementsCommandTest.java index 17bb61852042416a7a9606c5d082de6ac04f4b9b..efc14fabd446a75566b134306fdf54b86caedeb7 100644 --- a/model-command/src/test/java/lcsb/mapviewer/commands/MoveElementsCommandTest.java +++ b/model-command/src/test/java/lcsb/mapviewer/commands/MoveElementsCommandTest.java @@ -13,9 +13,11 @@ import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.model.map.BioEntity; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelComparator; import lcsb.mapviewer.model.map.reaction.Reaction; @@ -23,255 +25,255 @@ import lcsb.mapviewer.model.map.species.Element; public class MoveElementsCommandTest extends CommandTestFunctions { - ModelComparator modelComparator = new ModelComparator(); - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testMoveAlias() throws Exception { - try { - Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); - Model model2 = getModelForFile("testFiles/spliting_test_Case.xml", false); - Element alias = model.getElementByElementId("sa2"); - Element alias2 = model.getElementByElementId("sa1"); - double anotherAliasX = alias2.getX(); - double anotherAliasY = alias2.getY(); - - List<Object> list = new ArrayList<>(); - list.add(alias); - double x = alias.getX(); - double y = alias.getY(); - - double dx = 10; - double dy = 2; - - // models should be equal before move - assertEquals(0, modelComparator.compare(model, model2)); - - MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); - moveCommand.execute(); - - // after move models should be different - assertTrue(0 != modelComparator.compare(model, model2)); - - // check new coordinates - assertEquals(x + dx, alias.getX(), Configuration.EPSILON); - assertEquals(y + dy, alias.getY(), Configuration.EPSILON); - - // and check if another alias didn't change coordinates - assertEquals(anotherAliasX, alias2.getX(), Configuration.EPSILON); - assertEquals(anotherAliasY, alias2.getY(), Configuration.EPSILON); - - list = new ArrayList<>(); - list.add(model2.getElementByElementId("sa2")); - MoveElementsCommand moveCommand2 = new MoveElementsCommand(model2, list, dx, dy); - moveCommand2.execute(); - - // if we perfomr the same operator on the second model then they should be - // equal - assertEquals(0, modelComparator.compare(model, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testMoveSpecies() throws Exception { - try { - Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); - List<Object> list = new ArrayList<>(); - list.add(new Object()); - - MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, 10, 10); - moveCommand.execute(); - fail("Exception expected"); - - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAliasWithReaction() throws Exception { - try { - Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); - Model model2 = getModelForFile("testFiles/spliting_test_Case.xml", false); - Element alias = model.getElementByElementId("sa1"); - Element alias2 = model.getElementByElementId("sa2"); - double anotherAliasX = alias2.getX(); - double anotherAliasY = alias2.getY(); - Reaction reaction = model.getReactionByReactionId("re1"); - - List<Object> list = new ArrayList<>(); - list.add(alias); - double x = reaction.getReactants().get(0).getLine().getBeginPoint().getX(); - double y = reaction.getReactants().get(0).getLine().getBeginPoint().getY(); - - double dx = 10; - double dy = 2; - - // models should be equal before move - assertEquals(0, modelComparator.compare(model, model2)); - - MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); - moveCommand.execute(); - - // after move models should be different - assertTrue(0 != modelComparator.compare(model, model2)); - - // check new coordinates of reaction - assertEquals(x + dx, reaction.getReactants().get(0).getLine().getBeginPoint().getX(), Configuration.EPSILON); - assertEquals(y + dy, reaction.getReactants().get(0).getLine().getBeginPoint().getY(), Configuration.EPSILON); - - // and check if another alias didn't change coordinates - assertEquals(anotherAliasX, alias2.getX(), Configuration.EPSILON); - assertEquals(anotherAliasY, alias2.getY(), Configuration.EPSILON); - - list = new ArrayList<>(); - list.add(model2.getElementByElementId("sa1")); - MoveElementsCommand moveCommand2 = new MoveElementsCommand(model2, list, dx, dy); - moveCommand2.execute(); - - // if we perfomr the same operator on the second model then they should be - // equal - assertEquals(0, modelComparator.compare(model, model2)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testMoveReaction() throws Exception { - try { - Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); - Element alias2 = model.getElementByElementId("sa1"); - double anotherAliasX = alias2.getX(); - double anotherAliasY = alias2.getY(); - Reaction reaction = model.getReactionByReactionId("re1"); - - List<Object> list = new ArrayList<>(); - list.add(reaction); - double x = reaction.getReactants().get(0).getLine().getBeginPoint().getX(); - double y = reaction.getReactants().get(0).getLine().getBeginPoint().getY(); - - double x2 = reaction.getReactants().get(0).getLine().getEndPoint().getX(); - double y2 = reaction.getReactants().get(0).getLine().getEndPoint().getY(); - - double dx = 10; - double dy = 2; - - MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); - moveCommand.execute(); - - // check new coordinates of reaction (point attached to alias shouldn't - // move, the one not attached should move) - assertEquals(x, reaction.getReactants().get(0).getLine().getBeginPoint().getX(), Configuration.EPSILON); - assertEquals(y, reaction.getReactants().get(0).getLine().getBeginPoint().getY(), Configuration.EPSILON); - assertEquals(x2 + dx, reaction.getReactants().get(0).getLine().getEndPoint().getX(), Configuration.EPSILON); - assertEquals(y2 + dy, reaction.getReactants().get(0).getLine().getEndPoint().getY(), Configuration.EPSILON); - - // and check if another alias didn't change coordinates - assertEquals(anotherAliasX, alias2.getX(), Configuration.EPSILON); - assertEquals(anotherAliasY, alias2.getY(), Configuration.EPSILON); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUndo() throws Exception { - try { - Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); - Model model2 = getModelForFile("testFiles/spliting_test_Case.xml", false); - Element alias = model.getElementByElementId("sa2"); - - List<Object> list = new ArrayList<>(); - list.add(alias); - - double dx = 10; - double dy = 2; - - // models should be equal before move - assertEquals(0, modelComparator.compare(model, model2)); - - MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); - moveCommand.execute(); - - // after move models should be different - assertTrue(0 != modelComparator.compare(model, model2)); - - // undo command - moveCommand.undo(); - - // after undo they should be the same again - assertEquals(0, modelComparator.compare(model, model2)); - - moveCommand.redo(); - - // after redo they should be different again - assertTrue(0 != modelComparator.compare(model, model2)); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetAffectedRegion() throws Exception { - try { - Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); - Element alias = model.getElementByElementId("sa2"); - - List<Object> list = new ArrayList<>(); - list.add(alias); - double x = alias.getX(); - double y = alias.getY(); - - double dx = 10; - double dy = 2; - - double minx = x; - double maxx = alias.getWidth() + x + dx; - - double miny = y; - double maxy = alias.getHeight() + y + dy; - - MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); - assertNull(moveCommand.getAffectedRegion()); - moveCommand.execute(); - assertNotNull(moveCommand.getAffectedRegion()); - Rectangle2D affectedRegion = moveCommand.getAffectedRegion(); - assertEquals(minx, affectedRegion.getX(), Configuration.EPSILON); - assertEquals(miny, affectedRegion.getY(), Configuration.EPSILON); - assertEquals(maxx, affectedRegion.getX() + affectedRegion.getWidth(), Configuration.EPSILON); - assertEquals(maxy, affectedRegion.getY() + affectedRegion.getHeight(), Configuration.EPSILON); - - moveCommand.undo(); - - affectedRegion = moveCommand.getAffectedRegion(); - assertEquals(minx, affectedRegion.getX(), Configuration.EPSILON); - assertEquals(miny, affectedRegion.getY(), Configuration.EPSILON); - assertEquals(maxx, affectedRegion.getX() + affectedRegion.getWidth(), Configuration.EPSILON); - assertEquals(maxy, affectedRegion.getY() + affectedRegion.getHeight(), Configuration.EPSILON); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + ModelComparator modelComparator = new ModelComparator(); + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testMoveAlias() throws Exception { + try { + Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); + Model model2 = getModelForFile("testFiles/spliting_test_Case.xml", false); + Element alias = model.getElementByElementId("sa2"); + Element alias2 = model.getElementByElementId("sa1"); + double anotherAliasX = alias2.getX(); + double anotherAliasY = alias2.getY(); + + List<BioEntity> list = new ArrayList<>(); + list.add(alias); + double x = alias.getX(); + double y = alias.getY(); + + double dx = 10; + double dy = 2; + + // models should be equal before move + assertEquals(0, modelComparator.compare(model, model2)); + + MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); + moveCommand.execute(); + + // after move models should be different + assertTrue(0 != modelComparator.compare(model, model2)); + + // check new coordinates + assertEquals(x + dx, alias.getX(), Configuration.EPSILON); + assertEquals(y + dy, alias.getY(), Configuration.EPSILON); + + // and check if another alias didn't change coordinates + assertEquals(anotherAliasX, alias2.getX(), Configuration.EPSILON); + assertEquals(anotherAliasY, alias2.getY(), Configuration.EPSILON); + + list = new ArrayList<>(); + list.add(model2.getElementByElementId("sa2")); + MoveElementsCommand moveCommand2 = new MoveElementsCommand(model2, list, dx, dy); + moveCommand2.execute(); + + // if we perfomr the same operator on the second model then they should be + // equal + assertEquals(0, modelComparator.compare(model, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testMoveSpecies() throws Exception { + try { + Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); + List<BioEntity> list = new ArrayList<>(); + list.add(Mockito.mock(BioEntity.class)); + + MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, 10, 10); + moveCommand.execute(); + fail("Exception expected"); + + } catch (InvalidArgumentException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAliasWithReaction() throws Exception { + try { + Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); + Model model2 = getModelForFile("testFiles/spliting_test_Case.xml", false); + Element alias = model.getElementByElementId("sa1"); + Element alias2 = model.getElementByElementId("sa2"); + double anotherAliasX = alias2.getX(); + double anotherAliasY = alias2.getY(); + Reaction reaction = model.getReactionByReactionId("re1"); + + List<BioEntity> list = new ArrayList<>(); + list.add(alias); + double x = reaction.getReactants().get(0).getLine().getBeginPoint().getX(); + double y = reaction.getReactants().get(0).getLine().getBeginPoint().getY(); + + double dx = 10; + double dy = 2; + + // models should be equal before move + assertEquals(0, modelComparator.compare(model, model2)); + + MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); + moveCommand.execute(); + + // after move models should be different + assertTrue(0 != modelComparator.compare(model, model2)); + + // check new coordinates of reaction + assertEquals(x + dx, reaction.getReactants().get(0).getLine().getBeginPoint().getX(), Configuration.EPSILON); + assertEquals(y + dy, reaction.getReactants().get(0).getLine().getBeginPoint().getY(), Configuration.EPSILON); + + // and check if another alias didn't change coordinates + assertEquals(anotherAliasX, alias2.getX(), Configuration.EPSILON); + assertEquals(anotherAliasY, alias2.getY(), Configuration.EPSILON); + + list = new ArrayList<>(); + list.add(model2.getElementByElementId("sa1")); + MoveElementsCommand moveCommand2 = new MoveElementsCommand(model2, list, dx, dy); + moveCommand2.execute(); + + // if we perfomr the same operator on the second model then they should be + // equal + assertEquals(0, modelComparator.compare(model, model2)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testMoveReaction() throws Exception { + try { + Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); + Element alias2 = model.getElementByElementId("sa1"); + double anotherAliasX = alias2.getX(); + double anotherAliasY = alias2.getY(); + Reaction reaction = model.getReactionByReactionId("re1"); + + List<BioEntity> list = new ArrayList<>(); + list.add(reaction); + double x = reaction.getReactants().get(0).getLine().getBeginPoint().getX(); + double y = reaction.getReactants().get(0).getLine().getBeginPoint().getY(); + + double x2 = reaction.getReactants().get(0).getLine().getEndPoint().getX(); + double y2 = reaction.getReactants().get(0).getLine().getEndPoint().getY(); + + double dx = 10; + double dy = 2; + + MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); + moveCommand.execute(); + + // check new coordinates of reaction (point attached to alias shouldn't + // move, the one not attached should move) + assertEquals(x, reaction.getReactants().get(0).getLine().getBeginPoint().getX(), Configuration.EPSILON); + assertEquals(y, reaction.getReactants().get(0).getLine().getBeginPoint().getY(), Configuration.EPSILON); + assertEquals(x2 + dx, reaction.getReactants().get(0).getLine().getEndPoint().getX(), Configuration.EPSILON); + assertEquals(y2 + dy, reaction.getReactants().get(0).getLine().getEndPoint().getY(), Configuration.EPSILON); + + // and check if another alias didn't change coordinates + assertEquals(anotherAliasX, alias2.getX(), Configuration.EPSILON); + assertEquals(anotherAliasY, alias2.getY(), Configuration.EPSILON); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUndo() throws Exception { + try { + Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); + Model model2 = getModelForFile("testFiles/spliting_test_Case.xml", false); + Element alias = model.getElementByElementId("sa2"); + + List<BioEntity> list = new ArrayList<>(); + list.add(alias); + + double dx = 10; + double dy = 2; + + // models should be equal before move + assertEquals(0, modelComparator.compare(model, model2)); + + MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); + moveCommand.execute(); + + // after move models should be different + assertTrue(0 != modelComparator.compare(model, model2)); + + // undo command + moveCommand.undo(); + + // after undo they should be the same again + assertEquals(0, modelComparator.compare(model, model2)); + + moveCommand.redo(); + + // after redo they should be different again + assertTrue(0 != modelComparator.compare(model, model2)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetAffectedRegion() throws Exception { + try { + Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); + Element alias = model.getElementByElementId("sa2"); + + List<BioEntity> list = new ArrayList<>(); + list.add(alias); + double x = alias.getX(); + double y = alias.getY(); + + double dx = 10; + double dy = 2; + + double minx = x; + double maxx = alias.getWidth() + x + dx; + + double miny = y; + double maxy = alias.getHeight() + y + dy; + + MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); + assertNull(moveCommand.getAffectedRegion()); + moveCommand.execute(); + assertNotNull(moveCommand.getAffectedRegion()); + Rectangle2D affectedRegion = moveCommand.getAffectedRegion(); + assertEquals(minx, affectedRegion.getX(), Configuration.EPSILON); + assertEquals(miny, affectedRegion.getY(), Configuration.EPSILON); + assertEquals(maxx, affectedRegion.getX() + affectedRegion.getWidth(), Configuration.EPSILON); + assertEquals(maxy, affectedRegion.getY() + affectedRegion.getHeight(), Configuration.EPSILON); + + moveCommand.undo(); + + affectedRegion = moveCommand.getAffectedRegion(); + assertEquals(minx, affectedRegion.getX(), Configuration.EPSILON); + assertEquals(miny, affectedRegion.getY(), Configuration.EPSILON); + assertEquals(maxx, affectedRegion.getX() + affectedRegion.getWidth(), Configuration.EPSILON); + assertEquals(maxy, affectedRegion.getY() + affectedRegion.getHeight(), Configuration.EPSILON); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/InconsistentModelException.java b/model/src/main/java/lcsb/mapviewer/model/map/InconsistentModelException.java index 2cfa3c8905b6cfa9ad2f417de46b495675165d65..b685b338060a4adf6ea4e84ab74a7cb7bdd1738b 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/InconsistentModelException.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/InconsistentModelException.java @@ -22,6 +22,10 @@ public class InconsistentModelException extends Exception { super(message); } + public InconsistentModelException(String message, Throwable e) { + super(message, e); + } + public InconsistentModelException(Exception e) { super(e); } diff --git a/model/src/main/java/lcsb/mapviewer/modelutils/map/ElementUtils.java b/model/src/main/java/lcsb/mapviewer/modelutils/map/ElementUtils.java index 5313c5b44f9ddb33b98d4fc1981c46e7e9f43957..932fb236d818ac071d286672d21a0954b40d1bb3 100644 --- a/model/src/main/java/lcsb/mapviewer/modelutils/map/ElementUtils.java +++ b/model/src/main/java/lcsb/mapviewer/modelutils/map/ElementUtils.java @@ -260,7 +260,11 @@ public final class ElementUtils { } public String getElementTag(ReactionNode node) { - return "[" + node.getClass().getSimpleName() + "]" + getElementTag(node.getElement()); + String reactionPrefix = ""; + if (node.getReaction() != null) { + reactionPrefix = getElementTag(node.getReaction()).replaceAll("\t", ""); + } + return reactionPrefix + "[" + node.getClass().getSimpleName() + "]" + getElementTag(node.getElement()); } public String getElementTag(ModificationResidue mr) {