diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/AbstractElementXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/AbstractElementXmlParser.java index 4c8449fd5e790233a81bd3c2f9387b6ba600964a..fcd1d7833f8dbde1ddd24bdb5e766145aa7d3efc 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/AbstractElementXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/AbstractElementXmlParser.java @@ -1,194 +1,192 @@ -package lcsb.mapviewer.converter.model.celldesigner.species; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import lcsb.mapviewer.common.Pair; -import lcsb.mapviewer.common.XmlParser; -import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; -import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser; -import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement; -import lcsb.mapviewer.model.map.InconsistentModelException; -import lcsb.mapviewer.model.map.species.Element; - -/** - * Abstract class with the interface to parse element in CellDesigner file. - * - * @author Piotr Gawron - * - * @param <T> - * type of the celldesigner object to parse - * @param <S> - * type of the model object to be obtained - */ -public abstract class AbstractElementXmlParser<T extends CellDesignerElement<?>, S extends Element> extends XmlParser { - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private Logger logger = Logger.getLogger(AbstractElementXmlParser.class.getName()); - - /** - * List of special strings in CellDesigner that should be translated into some - * UTF characters. - */ - private List<Pair<String, String>> encodedStrings = new ArrayList<Pair<String, String>>(); - - /** - * Parser of the notes that allows to extract additional structurized data for - * the object. - */ - private RestAnnotationParser rap = new RestAnnotationParser(); - - /** - * Method that parses CellDesigner xml node and translate it into object. - * Returns a {@link Pair} containing CellDesigner identifier in - * {@link Pair#left} and element in {@link Pair#right}. - * - * @param node - * xml node be parsed - * @return {@link Pair} containing CellDesigner identifier in - * {@link Pair#left} and element parsed from xml node in - * {@link Pair#right}. - * @throws InvalidXmlSchemaException - * thrown when xml is invalid - */ - public abstract Pair<String, T> parseXmlElement(Node node) throws InvalidXmlSchemaException; - - /** - * Default constructor. - */ - protected AbstractElementXmlParser() { - encodedStrings.add(new Pair<String, String>("_underscore_", "_")); - encodedStrings.add(new Pair<String, String>("_BR_", "\n")); - encodedStrings.add(new Pair<String, String>("_br_", "\n")); - encodedStrings.add(new Pair<String, String>("_plus_", "+")); - encodedStrings.add(new Pair<String, String>("_minus_", "-")); - encodedStrings.add(new Pair<String, String>("_slash_", "/")); - encodedStrings.add(new Pair<String, String>("_space_", " ")); - encodedStrings.add(new Pair<String, String>("_Alpha_", "Α")); - encodedStrings.add(new Pair<String, String>("_alpha_", "α")); - encodedStrings.add(new Pair<String, String>("_Beta_", "Î’")); - encodedStrings.add(new Pair<String, String>("_beta_", "β")); - encodedStrings.add(new Pair<String, String>("_Gamma_", "Γ")); - encodedStrings.add(new Pair<String, String>("_gamma_", "γ")); - encodedStrings.add(new Pair<String, String>("_Delta_", "Δ")); - encodedStrings.add(new Pair<String, String>("_delta_", "δ")); - encodedStrings.add(new Pair<String, String>("_Epsilon_", "Ε")); - encodedStrings.add(new Pair<String, String>("_epsilon_", "ε")); - encodedStrings.add(new Pair<String, String>("_Zeta_", "Ζ")); - encodedStrings.add(new Pair<String, String>("_zeta_", "ζ")); - encodedStrings.add(new Pair<String, String>("_Eta_", "Η")); - encodedStrings.add(new Pair<String, String>("_eta_", "η")); - encodedStrings.add(new Pair<String, String>("_Theta_", "Θ")); - encodedStrings.add(new Pair<String, String>("_theta_", "θ")); - encodedStrings.add(new Pair<String, String>("_Iota_", "Ι")); - encodedStrings.add(new Pair<String, String>("_iota_", "ι")); - encodedStrings.add(new Pair<String, String>("_Kappa_", "Κ")); - encodedStrings.add(new Pair<String, String>("_kappa_", "κ")); - encodedStrings.add(new Pair<String, String>("_Lambda_", "Λ")); - encodedStrings.add(new Pair<String, String>("_lambda_", "λ")); - encodedStrings.add(new Pair<String, String>("_Mu_", "Îœ")); - encodedStrings.add(new Pair<String, String>("_mu_", "μ")); - encodedStrings.add(new Pair<String, String>("_Nu_", "Î")); - encodedStrings.add(new Pair<String, String>("_nu_", "ν")); - encodedStrings.add(new Pair<String, String>("_Xi_", "Ξ")); - encodedStrings.add(new Pair<String, String>("_xi_", "ξ")); - encodedStrings.add(new Pair<String, String>("_Omicron_", "Ο")); - encodedStrings.add(new Pair<String, String>("_omicron_", "ο")); - encodedStrings.add(new Pair<String, String>("_Pi_", "Î ")); - encodedStrings.add(new Pair<String, String>("_pi_", "Ï€")); - encodedStrings.add(new Pair<String, String>("_Rho_", "Ρ")); - encodedStrings.add(new Pair<String, String>("_rho_", "Ï")); - encodedStrings.add(new Pair<String, String>("_Sigma_", "Σ")); - encodedStrings.add(new Pair<String, String>("_sigma_", "σ")); - encodedStrings.add(new Pair<String, String>("_Tau_", "Τ")); - encodedStrings.add(new Pair<String, String>("_tau_", "Ï„")); - encodedStrings.add(new Pair<String, String>("_Upsilon_", "Î¥")); - encodedStrings.add(new Pair<String, String>("_upsilon_", "Ï…")); - encodedStrings.add(new Pair<String, String>("_Phi_", "Φ")); - encodedStrings.add(new Pair<String, String>("_phi_", "φ")); - encodedStrings.add(new Pair<String, String>("_Chi_", "Χ")); - encodedStrings.add(new Pair<String, String>("_chi_", "χ")); - encodedStrings.add(new Pair<String, String>("_Psi_", "Ψ")); - encodedStrings.add(new Pair<String, String>("_psi_", "ψ")); - encodedStrings.add(new Pair<String, String>("_Omega_", "Ω")); - encodedStrings.add(new Pair<String, String>("_omega_", "ω")); - } - - /** - * Parses CellDEsigner xml node that is given as a plain text into element. - * Returns a {@link Pair} containing CellDesigner identifier in - * {@link Pair#left} and element in {@link Pair#right}. - * - * @param xmlString - * node to parse - * @return {@link Pair} containing CellDesigner identifier in - * {@link Pair#left} and element parsed from xml node in - * {@link Pair#right}. - * @throws InvalidXmlSchemaException - * thrown when xmlString is invalid - */ - public Pair<String, T> parseXmlElement(String xmlString) throws InvalidXmlSchemaException { - Document doc = getXmlDocumentFromString(xmlString); - NodeList root = doc.getChildNodes(); - return parseXmlElement(root.item(0)); - - } - - /** - * Method transforms element into CellDesigner xml string. - * - * @param element - * object to be transformed - * @return CellDesigner xml string representing element - * @throws InconsistentModelException - * thrown when xml cannot be generated because structure of objects - * is invalid - */ - public abstract String toXml(S element) throws InconsistentModelException; - - /** - * This method decodes CellDesigner string with all known CellDesigner special - * tokens. - * - * @param name - * string to be decoded - * @return decoded string - */ - protected String decodeName(String name) { - String result = name; - for (Pair<String, String> pair : encodedStrings) { - result = result.replaceAll(pair.getLeft(), pair.getRight()); - } - return result; - } - - /** - * This method encodes {@link String} using CellDesigner special tokens. - * - * @param name - * string to be decoded - * @return decoded string - */ - protected String encodeName(String name) { - String result = name; - for (Pair<String, String> pair : encodedStrings) { - result = result.replace(pair.getRight(), pair.getLeft()); - } - return result; - } - - /** - * @return the rap - */ - protected RestAnnotationParser getRap() { - return rap; - } -} +package lcsb.mapviewer.converter.model.celldesigner.species; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import lcsb.mapviewer.common.Pair; +import lcsb.mapviewer.common.XmlParser; +import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; +import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser; +import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement; +import lcsb.mapviewer.model.map.InconsistentModelException; +import lcsb.mapviewer.model.map.species.Element; + +/** + * Abstract class with the interface to parse element in CellDesigner file. + * + * @author Piotr Gawron + * + * @param <T> + * type of the CellDesigner object to parse + * @param <S> + * type of the model object to be obtained + */ +public abstract class AbstractElementXmlParser<T extends CellDesignerElement<?>, S extends Element> extends XmlParser { + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private Logger logger = Logger.getLogger(AbstractElementXmlParser.class.getName()); + + /** + * List of special strings in CellDesigner that should be translated into some + * UTF characters. + */ + private List<Pair<String, String>> encodedStrings = new ArrayList<Pair<String, String>>(); + + /** + * Parser of the notes that allows to extract additional structured data for the + * object. + */ + private RestAnnotationParser rap = new RestAnnotationParser(); + + /** + * Method that parses CellDesigner xml node and translate it into object. + * Returns a {@link Pair} containing CellDesigner identifier in + * {@link Pair#left} and element in {@link Pair#right}. + * + * @param node + * xml node be parsed + * @return {@link Pair} containing CellDesigner identifier in {@link Pair#left} + * and element parsed from xml node in {@link Pair#right}. + * @throws InvalidXmlSchemaException + * thrown when xml is invalid + */ + public abstract Pair<String, T> parseXmlElement(Node node) throws InvalidXmlSchemaException; + + /** + * Default constructor. + */ + protected AbstractElementXmlParser() { + encodedStrings.add(new Pair<String, String>("_underscore_", "_")); + encodedStrings.add(new Pair<String, String>("_BR_", "\n")); + encodedStrings.add(new Pair<String, String>("_br_", "\n")); + encodedStrings.add(new Pair<String, String>("_plus_", "+")); + encodedStrings.add(new Pair<String, String>("_minus_", "-")); + encodedStrings.add(new Pair<String, String>("_slash_", "/")); + encodedStrings.add(new Pair<String, String>("_space_", " ")); + encodedStrings.add(new Pair<String, String>("_Alpha_", "Α")); + encodedStrings.add(new Pair<String, String>("_alpha_", "α")); + encodedStrings.add(new Pair<String, String>("_Beta_", "Î’")); + encodedStrings.add(new Pair<String, String>("_beta_", "β")); + encodedStrings.add(new Pair<String, String>("_Gamma_", "Γ")); + encodedStrings.add(new Pair<String, String>("_gamma_", "γ")); + encodedStrings.add(new Pair<String, String>("_Delta_", "Δ")); + encodedStrings.add(new Pair<String, String>("_delta_", "δ")); + encodedStrings.add(new Pair<String, String>("_Epsilon_", "Ε")); + encodedStrings.add(new Pair<String, String>("_epsilon_", "ε")); + encodedStrings.add(new Pair<String, String>("_Zeta_", "Ζ")); + encodedStrings.add(new Pair<String, String>("_zeta_", "ζ")); + encodedStrings.add(new Pair<String, String>("_Eta_", "Η")); + encodedStrings.add(new Pair<String, String>("_eta_", "η")); + encodedStrings.add(new Pair<String, String>("_Theta_", "Θ")); + encodedStrings.add(new Pair<String, String>("_theta_", "θ")); + encodedStrings.add(new Pair<String, String>("_Iota_", "Ι")); + encodedStrings.add(new Pair<String, String>("_iota_", "ι")); + encodedStrings.add(new Pair<String, String>("_Kappa_", "Κ")); + encodedStrings.add(new Pair<String, String>("_kappa_", "κ")); + encodedStrings.add(new Pair<String, String>("_Lambda_", "Λ")); + encodedStrings.add(new Pair<String, String>("_lambda_", "λ")); + encodedStrings.add(new Pair<String, String>("_Mu_", "Îœ")); + encodedStrings.add(new Pair<String, String>("_mu_", "μ")); + encodedStrings.add(new Pair<String, String>("_Nu_", "Î")); + encodedStrings.add(new Pair<String, String>("_nu_", "ν")); + encodedStrings.add(new Pair<String, String>("_Xi_", "Ξ")); + encodedStrings.add(new Pair<String, String>("_xi_", "ξ")); + encodedStrings.add(new Pair<String, String>("_Omicron_", "Ο")); + encodedStrings.add(new Pair<String, String>("_omicron_", "ο")); + encodedStrings.add(new Pair<String, String>("_Pi_", "Î ")); + encodedStrings.add(new Pair<String, String>("_pi_", "Ï€")); + encodedStrings.add(new Pair<String, String>("_Rho_", "Ρ")); + encodedStrings.add(new Pair<String, String>("_rho_", "Ï")); + encodedStrings.add(new Pair<String, String>("_Sigma_", "Σ")); + encodedStrings.add(new Pair<String, String>("_sigma_", "σ")); + encodedStrings.add(new Pair<String, String>("_Tau_", "Τ")); + encodedStrings.add(new Pair<String, String>("_tau_", "Ï„")); + encodedStrings.add(new Pair<String, String>("_Upsilon_", "Î¥")); + encodedStrings.add(new Pair<String, String>("_upsilon_", "Ï…")); + encodedStrings.add(new Pair<String, String>("_Phi_", "Φ")); + encodedStrings.add(new Pair<String, String>("_phi_", "φ")); + encodedStrings.add(new Pair<String, String>("_Chi_", "Χ")); + encodedStrings.add(new Pair<String, String>("_chi_", "χ")); + encodedStrings.add(new Pair<String, String>("_Psi_", "Ψ")); + encodedStrings.add(new Pair<String, String>("_psi_", "ψ")); + encodedStrings.add(new Pair<String, String>("_Omega_", "Ω")); + encodedStrings.add(new Pair<String, String>("_omega_", "ω")); + } + + /** + * Parses CellDEsigner xml node that is given as a plain text into element. + * Returns a {@link Pair} containing CellDesigner identifier in + * {@link Pair#left} and element in {@link Pair#right}. + * + * @param xmlString + * node to parse + * @return {@link Pair} containing CellDesigner identifier in {@link Pair#left} + * and element parsed from xml node in {@link Pair#right}. + * @throws InvalidXmlSchemaException + * thrown when xmlString is invalid + */ + public Pair<String, T> parseXmlElement(String xmlString) throws InvalidXmlSchemaException { + Document doc = getXmlDocumentFromString(xmlString); + NodeList root = doc.getChildNodes(); + return parseXmlElement(root.item(0)); + + } + + /** + * Method transforms element into CellDesigner xml string. + * + * @param element + * object to be transformed + * @return CellDesigner xml string representing element + * @throws InconsistentModelException + * thrown when xml cannot be generated because structure of objects is + * invalid + */ + public abstract String toXml(S element) throws InconsistentModelException; + + /** + * This method decodes CellDesigner string with all known CellDesigner special + * tokens. + * + * @param name + * string to be decoded + * @return decoded string + */ + protected String decodeName(String name) { + String result = name; + for (Pair<String, String> pair : encodedStrings) { + result = result.replaceAll(pair.getLeft(), pair.getRight()); + } + return result; + } + + /** + * This method encodes {@link String} using CellDesigner special tokens. + * + * @param name + * string to be decoded + * @return decoded string + */ + protected String encodeName(String name) { + String result = name; + for (Pair<String, String> pair : encodedStrings) { + result = result.replace(pair.getRight(), pair.getLeft()); + } + return result; + } + + /** + * @return the rap + */ + protected RestAnnotationParser getRap() { + return rap; + } +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/compartment/SquareCompartment.java b/model/src/main/java/lcsb/mapviewer/model/map/compartment/SquareCompartment.java index 7879103bd363065fc0ff6398888361a8293b8037..097944a19c420ad7bcc56a5e677afdf9b8bd81a2 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/compartment/SquareCompartment.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/compartment/SquareCompartment.java @@ -1,61 +1,61 @@ -package lcsb.mapviewer.model.map.compartment; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -/** - * This class defines compartment with oval shape. - * - * @author Piotr Gawron - * - */ -@Entity -@DiscriminatorValue("Square Compartment") -public class SquareCompartment extends Compartment { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Empty constructor required by hibernate. - */ - SquareCompartment() { - super(); - } - - /** - * Constructor that creates a compartment with the new shape and takes the - * reference data from the compartment given as parameter. - * - * @param original - * orignal compartment where the data was kept - */ - public SquareCompartment(Compartment original) { - super(original); - } - - /** - * Default constructor. - * - * @param elementId - * identifier of the compartment - */ - public SquareCompartment(String elementId) { - super(); - setElementId(elementId); - } - - @Override - public SquareCompartment copy() { - if (this.getClass() == SquareCompartment.class) { - return new SquareCompartment(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - -} +package lcsb.mapviewer.model.map.compartment; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +/** + * This class defines compartment with oval shape. + * + * @author Piotr Gawron + * + */ +@Entity +@DiscriminatorValue("Square Compartment") +public class SquareCompartment extends Compartment { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Empty constructor required by hibernate. + */ + SquareCompartment() { + super(); + } + + /** + * Constructor that creates a compartment with the new shape and takes the + * reference data from the compartment given as parameter. + * + * @param original + * original compartment where the data was kept + */ + public SquareCompartment(Compartment original) { + super(original); + } + + /** + * Default constructor. + * + * @param elementId + * identifier of the compartment + */ + public SquareCompartment(String elementId) { + super(); + setElementId(elementId); + } + + @Override + public SquareCompartment copy() { + if (this.getClass() == SquareCompartment.class) { + return new SquareCompartment(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/model/ModelComparator.java b/model/src/main/java/lcsb/mapviewer/model/map/model/ModelComparator.java index 58cfdbf3e5bc1c565288bc9d57aed499c16d58d2..cd1fee24d3d0081760c6e74233f7871b2ad606ae 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/model/ModelComparator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/model/ModelComparator.java @@ -84,7 +84,7 @@ public class ModelComparator implements Comparator<Model> { * first object to compare * @param arg1 * second object to compare - * @return if all fields are qual then returns 0. If they are different then + * @return if all fields are equal then returns 0. If they are different then * -1/1 is returned. */ private int internalCompare(Model arg0, Model arg1) { diff --git a/model/src/test/java/lcsb/mapviewer/model/map/compartment/SquareCompartmentTest.java b/model/src/test/java/lcsb/mapviewer/model/map/compartment/SquareCompartmentTest.java index ec25e462c6ae41066640b32024325293d5d66f8b..04be65cfe52f909e0a27305a186c9532b64a4a6e 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/compartment/SquareCompartmentTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/compartment/SquareCompartmentTest.java @@ -1,71 +1,74 @@ -package lcsb.mapviewer.model.map.compartment; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -public class SquareCompartmentTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new SquareCompartment()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - SquareCompartment original = new SquareCompartment("id"); - SquareCompartment copy = new SquareCompartment(original); - assertNotNull(copy); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - SquareCompartment original = new SquareCompartment(); - SquareCompartment copy = original.copy(); - assertNotNull(copy); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - SquareCompartment compartment = Mockito.spy(SquareCompartment.class); - compartment.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.compartment; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +public class SquareCompartmentTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new SquareCompartment()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + SquareCompartment original = new SquareCompartment("id"); + original.setName("test name"); + SquareCompartment copy = new SquareCompartment(original); + assertNotNull(copy); + assertEquals("test name", copy.getName()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + SquareCompartment original = new SquareCompartment(); + SquareCompartment copy = original.copy(); + assertNotNull(copy); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + SquareCompartment compartment = Mockito.spy(SquareCompartment.class); + compartment.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +}