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

Merge branch 'error-message' into 'master'

Error message improved

See merge request !576
parents 04fdb2ab c635293a
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!576Error message improved
Pipeline #8199 passed
Showing
with 463 additions and 425 deletions
...@@ -4,6 +4,7 @@ import org.apache.log4j.Logger; ...@@ -4,6 +4,7 @@ import org.apache.log4j.Logger;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection;
...@@ -150,6 +151,8 @@ public class SpeciesAliasXmlParser extends AbstractAliasXmlParser<Species> { ...@@ -150,6 +151,8 @@ public class SpeciesAliasXmlParser extends AbstractAliasXmlParser<Species> {
species.updateModelElementAfterLayoutAdded(result); species.updateModelElementAfterLayoutAdded(result);
return result; return result;
} catch (InvalidArgumentException e) {
throw new InvalidXmlSchemaException(errorPrefix + e.getMessage(), e);
} catch (NotImplementedException e) { } catch (NotImplementedException e) {
throw new InvalidXmlSchemaException(errorPrefix + "Problem with creating species", e); throw new InvalidXmlSchemaException(errorPrefix + "Problem with creating species", e);
} }
......
...@@ -156,8 +156,9 @@ public class ReactionToXml extends XmlParser { ...@@ -156,8 +156,9 @@ public class ReactionToXml extends XmlParser {
* @param reaction * @param reaction
* reaction for which list is generated * reaction for which list is generated
* @return xml node with list of modification * @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(); StringBuilder sb = new StringBuilder();
sb.append("<celldesigner:listOfModification>\n"); sb.append("<celldesigner:listOfModification>\n");
...@@ -312,15 +313,16 @@ public class ReactionToXml extends XmlParser { ...@@ -312,15 +313,16 @@ public class ReactionToXml extends XmlParser {
} }
/** /**
* Creates xml node for given modifer. * Creates xml node for given modifier.
* *
* @param modifier * @param modifier
* modifier to be transaformed * modifier to be transformed
* @param gate * @param gate
* operator to which modifier is connected (if any) * 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(); StringBuilder sb = new StringBuilder();
ModifierTypeUtils modifierTypeUtils = new ModifierTypeUtils(); ModifierTypeUtils modifierTypeUtils = new ModifierTypeUtils();
sb.append("<celldesigner:modification "); sb.append("<celldesigner:modification ");
...@@ -340,21 +342,26 @@ public class ReactionToXml extends XmlParser { ...@@ -340,21 +342,26 @@ public class ReactionToXml extends XmlParser {
line.setStartPoint(start); line.setStartPoint(start);
} }
List<Point2D> points = lineTransformation.getPointsFromLine(line); try {
if (points.size() > 0) { List<Point2D> points = lineTransformation.getPointsFromLine(line);
if (points.size() > 0) {
boolean first = true; boolean first = true;
sb.append(" editPoints=\""); sb.append(" editPoints=\"");
for (Point2D point : points) { for (Point2D point : points) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
sb.append(" "); 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"); sb.append(">\n");
...@@ -479,8 +486,9 @@ public class ReactionToXml extends XmlParser { ...@@ -479,8 +486,9 @@ public class ReactionToXml extends XmlParser {
* @param reaction * @param reaction
* reaction to be processed * reaction to be processed
* @return xml node representing annotation part * @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()); ReactionLineData rdl = ReactionLineData.getByReactionType(reaction.getClass());
if (rdl == null) { if (rdl == null) {
throw new InvalidArgumentException("Unknown reaction type: " + reaction.getClass()); throw new InvalidArgumentException("Unknown reaction type: " + reaction.getClass());
......
...@@ -135,7 +135,7 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions { ...@@ -135,7 +135,7 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions {
CellDesignerXmlParser parser = new CellDesignerXmlParser(); CellDesignerXmlParser parser = new CellDesignerXmlParser();
parser.createModel(new ConverterParams().filename("testFiles/invalid/sample10.xml")); parser.createModel(new ConverterParams().filename("testFiles/invalid/sample10.xml"));
fail("Exceptin expected"); fail("Exceptin expected");
} catch (InvalidArgumentException e) { } catch (InvalidInputDataExecption e) {
assertTrue(e.getMessage().contains("No type information for modification")); assertTrue(e.getMessage().contains("No type information for modification"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -15,9 +15,6 @@ dbschemadiff=management_scripts/db_schema_and_diff.sh ...@@ -15,9 +15,6 @@ dbschemadiff=management_scripts/db_schema_and_diff.sh
#Where source file of the debian package should be placed #Where source file of the debian package should be placed
SRC_DIR=debian/src SRC_DIR=debian/src
#where the documentation files are stored
DOC_DIR=doc
#File that should be deployed on tomcat #File that should be deployed on tomcat
TOMCAT_FILE=web/target/web-1.0.war TOMCAT_FILE=web/target/web-1.0.war
...@@ -42,7 +39,7 @@ mkdir $SRC_DIR ...@@ -42,7 +39,7 @@ mkdir $SRC_DIR
cp $TOMCAT_FILE $SRC_DIR/minerva.war cp $TOMCAT_FILE $SRC_DIR/minerva.war
#copy manual documentation #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 gzip -n $SRC_DIR/minerva.txt
#copy configuration of logrotate #copy configuration of logrotate
......
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.
...@@ -33,6 +33,14 @@ ...@@ -33,6 +33,14 @@
<version>${log4j.version}</version> <version>${log4j.version}</version>
</dependency> </dependency>
<!-- mockito used for testing -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
...@@ -40,6 +48,7 @@ ...@@ -40,6 +48,7 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -2,12 +2,16 @@ package lcsb.mapviewer.commands; ...@@ -2,12 +2,16 @@ package lcsb.mapviewer.commands;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidStateException; import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.reaction.Modifier; import lcsb.mapviewer.model.map.reaction.Modifier;
...@@ -17,8 +21,8 @@ import lcsb.mapviewer.model.map.reaction.Reactant; ...@@ -17,8 +21,8 @@ import lcsb.mapviewer.model.map.reaction.Reactant;
import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.reaction.ReactionNode; import lcsb.mapviewer.model.map.reaction.ReactionNode;
import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import org.apache.log4j.Logger; import lcsb.mapviewer.model.map.species.field.SpeciesWithModificationResidue;
/** /**
* Command which moves elements in model by dx, dy coordinates. * Command which moves elements in model by dx, dy coordinates.
...@@ -28,154 +32,159 @@ import org.apache.log4j.Logger; ...@@ -28,154 +32,159 @@ import org.apache.log4j.Logger;
*/ */
public class MoveElementsCommand extends ModelCommand { public class MoveElementsCommand extends ModelCommand {
/** /**
* Default class logger. * Default class logger.
*/ */
private final Logger logger = Logger.getLogger(MoveElementsCommand.class); private final Logger logger = Logger.getLogger(MoveElementsCommand.class);
/** /**
* Delta x. * Delta x.
*/ */
private double dx; private double dx;
/** /**
* Delta y. * Delta y.
*/ */
private double dy; private double dy;
/** /**
* List of objects to move. * List of objects to move.
*/ */
private List<Object> objectsToMove = new ArrayList<>(); private List<Object> objectsToMove = new ArrayList<>();
/** /**
* Default constructor. * Default constructor.
* *
* @param model * @param model
* model to move * model to move
* @param elements * @param elements
* elements that should be moved * elements that should be moved
* @param dx * @param dx
* delta x * delta x
* @param dy * @param dy
* delat y * delta y
*/ */
public MoveElementsCommand(Model model, List<Object> elements, double dx, double dy) { public MoveElementsCommand(Model model, Collection<? extends BioEntity> elements, double dx, double dy) {
super(model); super(model);
this.dx = dx; this.dx = dx;
this.dy = dy; this.dy = dy;
for (Object object : elements) { for (Object object : elements) {
if (object instanceof Element) { if (object instanceof Element) {
if (((Element) object).getModel() != model) { if (((Element) object).getModel() != model) {
throw new InvalidArgumentException("Object doesnt belong to specified model: " + object); throw new InvalidArgumentException("Object doesnt belong to specified model: " + object);
} }
} else if (object instanceof Reaction) { } else if (object instanceof Reaction) {
if (((Reaction) object).getModel() != model) { if (((Reaction) object).getModel() != model) {
throw new InvalidArgumentException("Object doesnt belong to specified model: " + object); throw new InvalidArgumentException("Object doesnt belong to specified model: " + object);
} }
} else { } else {
throw new InvalidArgumentException("Cannot move element: " + object); throw new InvalidArgumentException("Cannot move element: " + object);
} }
} }
objectsToMove = elements; objectsToMove.addAll(elements);
} }
@Override @Override
protected void undoImplementation() { protected void undoImplementation() {
dx = -dx; dx = -dx;
dy = -dy; dy = -dy;
executeImplementation(); executeImplementation();
dx = -dx; dx = -dx;
dy = -dy; dy = -dy;
setStatus(ModelCommandStatus.UNDONE); setStatus(ModelCommandStatus.UNDONE);
} }
@Override @Override
protected void redoImplementation() { protected void redoImplementation() {
executeImplementation(); executeImplementation();
setStatus(ModelCommandStatus.EXECUTED); setStatus(ModelCommandStatus.EXECUTED);
} }
@Override @Override
protected void executeImplementation() { protected void executeImplementation() {
Set<Element> aliases = new HashSet<>(); Set<Element> aliases = new HashSet<>();
for (Object object : objectsToMove) { for (Object object : objectsToMove) {
if (object instanceof Element) { if (object instanceof Element) {
Element alias = (Element) object; Element alias = (Element) object;
includeInAffectedRegion(alias); includeInAffectedRegion(alias);
alias.setX(alias.getX() + dx); alias.setX(alias.getX() + dx);
alias.setY(alias.getY() + dy); alias.setY(alias.getY() + dy);
if (alias instanceof Compartment) { if (alias instanceof Compartment) {
((Compartment) alias) ((Compartment) alias)
.setNamePoint(((Compartment) alias).getNamePoint().getX() + dx, ((Compartment) alias).getNamePoint().getY() + dy); .setNamePoint(((Compartment) alias).getNamePoint().getX() + dx,
} ((Compartment) alias).getNamePoint().getY() + dy);
}
includeInAffectedRegion(alias); if (alias instanceof SpeciesWithModificationResidue) {
for (ModificationResidue mr : ((SpeciesWithModificationResidue) alias).getModificationResidues()) {
aliases.add(alias); Point2D position = mr.getPosition();
} else if (object instanceof Reaction) { position.setLocation(position.getX() + dx, position.getY() + dy);
Reaction reaction = (Reaction) object; }
for (Reactant node : reaction.getReactants()) { }
for (int i = 1; i < node.getLine().getPoints().size(); i++) { includeInAffectedRegion(alias);
Point2D point = node.getLine().getPoints().get(i);
logger.debug("Moving point: " + point); aliases.add(alias);
point.setLocation(point.getX() + dx, point.getY() + dy); } else if (object instanceof Reaction) {
} Reaction reaction = (Reaction) object;
} for (Reactant node : reaction.getReactants()) {
for (Product node : reaction.getProducts()) { for (int i = 1; i < node.getLine().getPoints().size(); i++) {
for (int i = 0; i < node.getLine().getPoints().size() - 1; i++) { Point2D point = node.getLine().getPoints().get(i);
Point2D point = node.getLine().getPoints().get(i); node.getLine().getPoints().set(i, new Point2D.Double(point.getX() + dx, point.getY() + dy));
point.setLocation(point.getX() + dx, point.getY() + dy); }
} }
} for (Product node : reaction.getProducts()) {
for (Modifier node : reaction.getModifiers()) { for (int i = 0; i < node.getLine().getPoints().size() - 1; i++) {
for (int i = 1; i < node.getLine().getPoints().size(); i++) { Point2D point = node.getLine().getPoints().get(i);
Point2D point = node.getLine().getPoints().get(i); node.getLine().getPoints().set(i, new Point2D.Double(point.getX() + dx, point.getY() + dy));
point.setLocation(point.getX() + dx, point.getY() + dy); }
} }
} for (Modifier node : reaction.getModifiers()) {
for (NodeOperator node : reaction.getOperators()) { for (int i = 1; i < node.getLine().getPoints().size(); i++) {
for (int i = 0; i < node.getLine().getPoints().size(); i++) { Point2D point = node.getLine().getPoints().get(i);
Point2D point = node.getLine().getPoints().get(i); node.getLine().getPoints().set(i, new Point2D.Double(point.getX() + dx, point.getY() + dy));
point.setLocation(point.getX() + dx, point.getY() + dy); }
} }
} for (NodeOperator node : reaction.getOperators()) {
includeInAffectedRegion(reaction); for (int i = 0; i < node.getLine().getPoints().size(); i++) {
} else { Point2D point = node.getLine().getPoints().get(i);
throw new InvalidStateException("Unknown class type: " + object); node.getLine().getPoints().set(i, new Point2D.Double(point.getX() + dx, point.getY() + dy));
} }
} }
if (aliases.size() > 0) { includeInAffectedRegion(reaction);
// TODO this must be improved, we cannot do full search on every move } else {
for (Reaction reaction : getModel().getReactions()) { throw new InvalidStateException("Unknown class type: " + object);
for (ReactionNode node : reaction.getReactionNodes()) { }
if (aliases.contains(node.getElement())) { }
if (node instanceof Reactant) { if (aliases.size() > 0) {
Point2D point = node.getLine().getBeginPoint(); // TODO this must be improved, we cannot do full search on every move
point.setLocation(point.getX() + dx, point.getY() + dy); for (Reaction reaction : getModel().getReactions()) {
for (ReactionNode node : reaction.getReactionNodes()) {
// we don't have to include point that we change as it's already if (aliases.contains(node.getElement())) {
// on the border of the element if (node instanceof Reactant) {
includeInAffectedRegion(node.getLine().getPoints().get(1)); Point2D point = node.getLine().getBeginPoint();
} else if (node instanceof Modifier) { point.setLocation(point.getX() + dx, point.getY() + dy);
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
// we don't have to include point that we change as it's already // on the border of the element
// on the border of the element includeInAffectedRegion(node.getLine().getPoints().get(1));
includeInAffectedRegion(node.getLine().getPoints().get(1)); } else if (node instanceof Modifier) {
} else if (node instanceof Product) { Point2D point = node.getLine().getBeginPoint();
Point2D point = node.getLine().getEndPoint(); point.setLocation(point.getX() + dx, point.getY() + dy);
point.setLocation(point.getX() + dx, point.getY() + dy); // we don't have to include point that we change as it's already
// we don't have to include point that we change as it's already // on the border of the element
// on the border of the element includeInAffectedRegion(node.getLine().getPoints().get(1));
includeInAffectedRegion(node.getLine().getPoints().get(node.getLine().getPoints().size() - 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));
} }
}
}
}
}
}
} }
...@@ -13,9 +13,11 @@ import java.util.List; ...@@ -13,9 +13,11 @@ import java.util.List;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito;
import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.exception.InvalidArgumentException; 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.Model;
import lcsb.mapviewer.model.map.model.ModelComparator; import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.Reaction;
...@@ -23,255 +25,255 @@ import lcsb.mapviewer.model.map.species.Element; ...@@ -23,255 +25,255 @@ import lcsb.mapviewer.model.map.species.Element;
public class MoveElementsCommandTest extends CommandTestFunctions { public class MoveElementsCommandTest extends CommandTestFunctions {
ModelComparator modelComparator = new ModelComparator(); ModelComparator modelComparator = new ModelComparator();
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
} }
@Test @Test
public void testMoveAlias() throws Exception { public void testMoveAlias() throws Exception {
try { try {
Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); Model model = getModelForFile("testFiles/spliting_test_Case.xml", false);
Model model2 = getModelForFile("testFiles/spliting_test_Case.xml", false); Model model2 = getModelForFile("testFiles/spliting_test_Case.xml", false);
Element alias = model.getElementByElementId("sa2"); Element alias = model.getElementByElementId("sa2");
Element alias2 = model.getElementByElementId("sa1"); Element alias2 = model.getElementByElementId("sa1");
double anotherAliasX = alias2.getX(); double anotherAliasX = alias2.getX();
double anotherAliasY = alias2.getY(); double anotherAliasY = alias2.getY();
List<Object> list = new ArrayList<>(); List<BioEntity> list = new ArrayList<>();
list.add(alias); list.add(alias);
double x = alias.getX(); double x = alias.getX();
double y = alias.getY(); double y = alias.getY();
double dx = 10; double dx = 10;
double dy = 2; double dy = 2;
// models should be equal before move // models should be equal before move
assertEquals(0, modelComparator.compare(model, model2)); assertEquals(0, modelComparator.compare(model, model2));
MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy);
moveCommand.execute(); moveCommand.execute();
// after move models should be different // after move models should be different
assertTrue(0 != modelComparator.compare(model, model2)); assertTrue(0 != modelComparator.compare(model, model2));
// check new coordinates // check new coordinates
assertEquals(x + dx, alias.getX(), Configuration.EPSILON); assertEquals(x + dx, alias.getX(), Configuration.EPSILON);
assertEquals(y + dy, alias.getY(), Configuration.EPSILON); assertEquals(y + dy, alias.getY(), Configuration.EPSILON);
// and check if another alias didn't change coordinates // and check if another alias didn't change coordinates
assertEquals(anotherAliasX, alias2.getX(), Configuration.EPSILON); assertEquals(anotherAliasX, alias2.getX(), Configuration.EPSILON);
assertEquals(anotherAliasY, alias2.getY(), Configuration.EPSILON); assertEquals(anotherAliasY, alias2.getY(), Configuration.EPSILON);
list = new ArrayList<>(); list = new ArrayList<>();
list.add(model2.getElementByElementId("sa2")); list.add(model2.getElementByElementId("sa2"));
MoveElementsCommand moveCommand2 = new MoveElementsCommand(model2, list, dx, dy); MoveElementsCommand moveCommand2 = new MoveElementsCommand(model2, list, dx, dy);
moveCommand2.execute(); moveCommand2.execute();
// if we perfomr the same operator on the second model then they should be // if we perfomr the same operator on the second model then they should be
// equal // equal
assertEquals(0, modelComparator.compare(model, model2)); assertEquals(0, modelComparator.compare(model, model2));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
} }
@Test @Test
public void testMoveSpecies() throws Exception { public void testMoveSpecies() throws Exception {
try { try {
Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); Model model = getModelForFile("testFiles/spliting_test_Case.xml", false);
List<Object> list = new ArrayList<>(); List<BioEntity> list = new ArrayList<>();
list.add(new Object()); list.add(Mockito.mock(BioEntity.class));
MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, 10, 10); MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, 10, 10);
moveCommand.execute(); moveCommand.execute();
fail("Exception expected"); fail("Exception expected");
} catch (InvalidArgumentException e) { } catch (InvalidArgumentException e) {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
} }
@Test @Test
public void testAliasWithReaction() throws Exception { public void testAliasWithReaction() throws Exception {
try { try {
Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); Model model = getModelForFile("testFiles/spliting_test_Case.xml", false);
Model model2 = getModelForFile("testFiles/spliting_test_Case.xml", false); Model model2 = getModelForFile("testFiles/spliting_test_Case.xml", false);
Element alias = model.getElementByElementId("sa1"); Element alias = model.getElementByElementId("sa1");
Element alias2 = model.getElementByElementId("sa2"); Element alias2 = model.getElementByElementId("sa2");
double anotherAliasX = alias2.getX(); double anotherAliasX = alias2.getX();
double anotherAliasY = alias2.getY(); double anotherAliasY = alias2.getY();
Reaction reaction = model.getReactionByReactionId("re1"); Reaction reaction = model.getReactionByReactionId("re1");
List<Object> list = new ArrayList<>(); List<BioEntity> list = new ArrayList<>();
list.add(alias); list.add(alias);
double x = reaction.getReactants().get(0).getLine().getBeginPoint().getX(); double x = reaction.getReactants().get(0).getLine().getBeginPoint().getX();
double y = reaction.getReactants().get(0).getLine().getBeginPoint().getY(); double y = reaction.getReactants().get(0).getLine().getBeginPoint().getY();
double dx = 10; double dx = 10;
double dy = 2; double dy = 2;
// models should be equal before move // models should be equal before move
assertEquals(0, modelComparator.compare(model, model2)); assertEquals(0, modelComparator.compare(model, model2));
MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy);
moveCommand.execute(); moveCommand.execute();
// after move models should be different // after move models should be different
assertTrue(0 != modelComparator.compare(model, model2)); assertTrue(0 != modelComparator.compare(model, model2));
// check new coordinates of reaction // check new coordinates of reaction
assertEquals(x + dx, reaction.getReactants().get(0).getLine().getBeginPoint().getX(), Configuration.EPSILON); assertEquals(x + dx, reaction.getReactants().get(0).getLine().getBeginPoint().getX(), Configuration.EPSILON);
assertEquals(y + dy, reaction.getReactants().get(0).getLine().getBeginPoint().getY(), Configuration.EPSILON); assertEquals(y + dy, reaction.getReactants().get(0).getLine().getBeginPoint().getY(), Configuration.EPSILON);
// and check if another alias didn't change coordinates // and check if another alias didn't change coordinates
assertEquals(anotherAliasX, alias2.getX(), Configuration.EPSILON); assertEquals(anotherAliasX, alias2.getX(), Configuration.EPSILON);
assertEquals(anotherAliasY, alias2.getY(), Configuration.EPSILON); assertEquals(anotherAliasY, alias2.getY(), Configuration.EPSILON);
list = new ArrayList<>(); list = new ArrayList<>();
list.add(model2.getElementByElementId("sa1")); list.add(model2.getElementByElementId("sa1"));
MoveElementsCommand moveCommand2 = new MoveElementsCommand(model2, list, dx, dy); MoveElementsCommand moveCommand2 = new MoveElementsCommand(model2, list, dx, dy);
moveCommand2.execute(); moveCommand2.execute();
// if we perfomr the same operator on the second model then they should be // if we perfomr the same operator on the second model then they should be
// equal // equal
assertEquals(0, modelComparator.compare(model, model2)); assertEquals(0, modelComparator.compare(model, model2));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
} }
@Test @Test
public void testMoveReaction() throws Exception { public void testMoveReaction() throws Exception {
try { try {
Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); Model model = getModelForFile("testFiles/spliting_test_Case.xml", false);
Element alias2 = model.getElementByElementId("sa1"); Element alias2 = model.getElementByElementId("sa1");
double anotherAliasX = alias2.getX(); double anotherAliasX = alias2.getX();
double anotherAliasY = alias2.getY(); double anotherAliasY = alias2.getY();
Reaction reaction = model.getReactionByReactionId("re1"); Reaction reaction = model.getReactionByReactionId("re1");
List<Object> list = new ArrayList<>(); List<BioEntity> list = new ArrayList<>();
list.add(reaction); list.add(reaction);
double x = reaction.getReactants().get(0).getLine().getBeginPoint().getX(); double x = reaction.getReactants().get(0).getLine().getBeginPoint().getX();
double y = reaction.getReactants().get(0).getLine().getBeginPoint().getY(); double y = reaction.getReactants().get(0).getLine().getBeginPoint().getY();
double x2 = reaction.getReactants().get(0).getLine().getEndPoint().getX(); double x2 = reaction.getReactants().get(0).getLine().getEndPoint().getX();
double y2 = reaction.getReactants().get(0).getLine().getEndPoint().getY(); double y2 = reaction.getReactants().get(0).getLine().getEndPoint().getY();
double dx = 10; double dx = 10;
double dy = 2; double dy = 2;
MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy);
moveCommand.execute(); moveCommand.execute();
// check new coordinates of reaction (point attached to alias shouldn't // check new coordinates of reaction (point attached to alias shouldn't
// move, the one not attached should move) // move, the one not attached should move)
assertEquals(x, reaction.getReactants().get(0).getLine().getBeginPoint().getX(), Configuration.EPSILON); assertEquals(x, reaction.getReactants().get(0).getLine().getBeginPoint().getX(), Configuration.EPSILON);
assertEquals(y, reaction.getReactants().get(0).getLine().getBeginPoint().getY(), 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(x2 + dx, reaction.getReactants().get(0).getLine().getEndPoint().getX(), Configuration.EPSILON);
assertEquals(y2 + dy, reaction.getReactants().get(0).getLine().getEndPoint().getY(), Configuration.EPSILON); assertEquals(y2 + dy, reaction.getReactants().get(0).getLine().getEndPoint().getY(), Configuration.EPSILON);
// and check if another alias didn't change coordinates // and check if another alias didn't change coordinates
assertEquals(anotherAliasX, alias2.getX(), Configuration.EPSILON); assertEquals(anotherAliasX, alias2.getX(), Configuration.EPSILON);
assertEquals(anotherAliasY, alias2.getY(), Configuration.EPSILON); assertEquals(anotherAliasY, alias2.getY(), Configuration.EPSILON);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
} }
@Test @Test
public void testUndo() throws Exception { public void testUndo() throws Exception {
try { try {
Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); Model model = getModelForFile("testFiles/spliting_test_Case.xml", false);
Model model2 = getModelForFile("testFiles/spliting_test_Case.xml", false); Model model2 = getModelForFile("testFiles/spliting_test_Case.xml", false);
Element alias = model.getElementByElementId("sa2"); Element alias = model.getElementByElementId("sa2");
List<Object> list = new ArrayList<>(); List<BioEntity> list = new ArrayList<>();
list.add(alias); list.add(alias);
double dx = 10; double dx = 10;
double dy = 2; double dy = 2;
// models should be equal before move // models should be equal before move
assertEquals(0, modelComparator.compare(model, model2)); assertEquals(0, modelComparator.compare(model, model2));
MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy);
moveCommand.execute(); moveCommand.execute();
// after move models should be different // after move models should be different
assertTrue(0 != modelComparator.compare(model, model2)); assertTrue(0 != modelComparator.compare(model, model2));
// undo command // undo command
moveCommand.undo(); moveCommand.undo();
// after undo they should be the same again // after undo they should be the same again
assertEquals(0, modelComparator.compare(model, model2)); assertEquals(0, modelComparator.compare(model, model2));
moveCommand.redo(); moveCommand.redo();
// after redo they should be different again // after redo they should be different again
assertTrue(0 != modelComparator.compare(model, model2)); assertTrue(0 != modelComparator.compare(model, model2));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
} }
@Test @Test
public void testGetAffectedRegion() throws Exception { public void testGetAffectedRegion() throws Exception {
try { try {
Model model = getModelForFile("testFiles/spliting_test_Case.xml", false); Model model = getModelForFile("testFiles/spliting_test_Case.xml", false);
Element alias = model.getElementByElementId("sa2"); Element alias = model.getElementByElementId("sa2");
List<Object> list = new ArrayList<>(); List<BioEntity> list = new ArrayList<>();
list.add(alias); list.add(alias);
double x = alias.getX(); double x = alias.getX();
double y = alias.getY(); double y = alias.getY();
double dx = 10; double dx = 10;
double dy = 2; double dy = 2;
double minx = x; double minx = x;
double maxx = alias.getWidth() + x + dx; double maxx = alias.getWidth() + x + dx;
double miny = y; double miny = y;
double maxy = alias.getHeight() + y + dy; double maxy = alias.getHeight() + y + dy;
MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy); MoveElementsCommand moveCommand = new MoveElementsCommand(model, list, dx, dy);
assertNull(moveCommand.getAffectedRegion()); assertNull(moveCommand.getAffectedRegion());
moveCommand.execute(); moveCommand.execute();
assertNotNull(moveCommand.getAffectedRegion()); assertNotNull(moveCommand.getAffectedRegion());
Rectangle2D affectedRegion = moveCommand.getAffectedRegion(); Rectangle2D affectedRegion = moveCommand.getAffectedRegion();
assertEquals(minx, affectedRegion.getX(), Configuration.EPSILON); assertEquals(minx, affectedRegion.getX(), Configuration.EPSILON);
assertEquals(miny, affectedRegion.getY(), Configuration.EPSILON); assertEquals(miny, affectedRegion.getY(), Configuration.EPSILON);
assertEquals(maxx, affectedRegion.getX() + affectedRegion.getWidth(), Configuration.EPSILON); assertEquals(maxx, affectedRegion.getX() + affectedRegion.getWidth(), Configuration.EPSILON);
assertEquals(maxy, affectedRegion.getY() + affectedRegion.getHeight(), Configuration.EPSILON); assertEquals(maxy, affectedRegion.getY() + affectedRegion.getHeight(), Configuration.EPSILON);
moveCommand.undo(); moveCommand.undo();
affectedRegion = moveCommand.getAffectedRegion(); affectedRegion = moveCommand.getAffectedRegion();
assertEquals(minx, affectedRegion.getX(), Configuration.EPSILON); assertEquals(minx, affectedRegion.getX(), Configuration.EPSILON);
assertEquals(miny, affectedRegion.getY(), Configuration.EPSILON); assertEquals(miny, affectedRegion.getY(), Configuration.EPSILON);
assertEquals(maxx, affectedRegion.getX() + affectedRegion.getWidth(), Configuration.EPSILON); assertEquals(maxx, affectedRegion.getX() + affectedRegion.getWidth(), Configuration.EPSILON);
assertEquals(maxy, affectedRegion.getY() + affectedRegion.getHeight(), Configuration.EPSILON); assertEquals(maxy, affectedRegion.getY() + affectedRegion.getHeight(), Configuration.EPSILON);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
} }
} }
...@@ -22,6 +22,10 @@ public class InconsistentModelException extends Exception { ...@@ -22,6 +22,10 @@ public class InconsistentModelException extends Exception {
super(message); super(message);
} }
public InconsistentModelException(String message, Throwable e) {
super(message, e);
}
public InconsistentModelException(Exception e) { public InconsistentModelException(Exception e) {
super(e); super(e);
} }
......
...@@ -260,7 +260,11 @@ public final class ElementUtils { ...@@ -260,7 +260,11 @@ public final class ElementUtils {
} }
public String getElementTag(ReactionNode node) { 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) { public String getElementTag(ModificationResidue mr) {
......
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