Commit 4a1afe90 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

BioEntity contain information about z-index

parent a96f48c2
......@@ -197,7 +197,22 @@ public interface BioEntity extends Serializable {
Model getModel();
String getElementId();
BioEntity copy();
/**
* Returns z-index of the graphical representation.
*
* @return z-index of the graphical representation
*/
Integer getZ();
/**
* Sets z-index of the graphical representation.
*
* @param z
* z-index of the graphical representation
*/
void setZ(Integer z);
}
......@@ -181,6 +181,11 @@ public class Reaction implements BioEntity {
*/
private String visibilityLevel = "";
/**
* Z-index of elements on the map.
*/
private Integer z = null;
/**
* Lists of all synonyms used for describing this element.
*/
......@@ -232,6 +237,7 @@ public class Reaction implements BioEntity {
addNode(node);
}
z = original.getZ();
notes = original.getNotes();
idReaction = original.getIdReaction();
name = original.getName();
......@@ -904,4 +910,14 @@ public class Reaction implements BioEntity {
public void setKinetics(SbmlKinetics kinetics) {
this.kinetics = kinetics;
}
@Override
public Integer getZ() {
return z;
}
@Override
public void setZ(Integer z) {
this.z = z;
}
}
......@@ -38,6 +38,10 @@ public class ModulationReaction extends Reaction implements SimpleReactionInterf
super(result);
}
public ModulationReaction(String reactionId) {
super(reactionId);
}
@Override
public String getStringType() {
return "Modulation";
......
......@@ -144,6 +144,11 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument {
*/
private Double y;
/**
* Z-index of elements on the map.
*/
private Integer z = null;
/**
* Width of the element.
*/
......@@ -264,6 +269,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument {
elementId = original.getElementId();
x = original.getX();
y = original.getY();
z = original.getZ();
width = original.getWidth();
height = original.getHeight();
fontSize = original.getFontSize();
......@@ -1069,4 +1075,14 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument {
setWidth(border.getWidth());
setHeight(border.getHeight());
}
@Override
public Integer getZ() {
return z;
}
@Override
public void setZ(Integer z) {
this.z = z;
}
}
\ No newline at end of file
-- add z-index to all elements in the database in similar way as they are drawn right now
alter table element_table add column z integer;
alter table reaction_table add column z integer;
with v_element_table as
(
select id, row_number() over (order by width*height desc, id) as rn from element_table where not element_type_db like '%COMPARTMENT%' and compartment_id is null and idcomplexdb is null
)
update element_table set z = v_element_table.rn
from v_element_table
where element_table.id = v_element_table.id;
with v_reaction_table as
(
select id, row_number() over (order by id) as rn from reaction_table
)
update reaction_table set z = v_reaction_table.rn + (select max(z) from element_table)
from v_reaction_table
where reaction_table.id = v_reaction_table.id;
with v_element_table as
(
select id, row_number() over (order by width*height desc, id) + (select max(z) from reaction_table) as rn from element_table where compartment_id is null and idcomplexdb is null and z is null
)
update element_table set z = v_element_table.rn
from v_element_table
where element_table.id = v_element_table.id;
DO $$
DECLARE
begin
for i in 1..10 loop
with v_element_table as
(
select id, row_number() over (order by width*height desc, id) + (select max(z) from element_table) as rn from element_table where z is null and compartment_id in (select id from element_table where z is not null) and idcomplexdb is null
)
update element_table set z = v_element_table.rn
from v_element_table
where element_table.id = v_element_table.id;
end loop;
end;
$$
;
DO $$
DECLARE
begin
for i in 1..10 loop
with v_element_table as
(
select id, row_number() over (order by width*height desc, id) + (select max(z) from element_table) as rn from element_table where z is null and idcomplexdb in (select id from element_table where z is not null)
)
update element_table set z = v_element_table.rn
from v_element_table
where element_table.id = v_element_table.id;
end loop;
end;
$$
;
-- just in case 10 loops were not enough
update element_table set z = (select max(z) from element_table) where z is null;
ALTER TABLE element_table ALTER COLUMN z SET NOT NULL;
ALTER TABLE reaction_table ALTER COLUMN z SET NOT NULL;
......@@ -40,6 +40,16 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.reaction.type.ModulationReaction;
import lcsb.mapviewer.model.map.reaction.type.TransportReaction;
import lcsb.mapviewer.model.map.species.AntisenseRna;
import lcsb.mapviewer.model.map.species.Chemical;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Ion;
import lcsb.mapviewer.model.map.species.Phenotype;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.persist.dao.cache.CacheQueryDao;
......@@ -103,6 +113,10 @@ public abstract class PersistTestFunctions {
@Autowired
protected CacheTypeDao cacheTypeDao;
protected int identifierCounter = 0;
private int zIndex = 0;
protected String readFile(String file) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(file));
......@@ -286,4 +300,88 @@ public abstract class PersistTestFunctions {
in.close();
return tmp.toString();
}
protected Compartment createCompartment(double x, double y, double width, double height, String compartmentId) {
Compartment compartment = new Compartment(compartmentId);
compartment.setX(x);
compartment.setY(y);
compartment.setZ(zIndex++);
compartment.setWidth(width);
compartment.setHeight(height);
return compartment;
}
protected Compartment createCompartment(String compartmentId) {
return createCompartment(10, 20, 100, 200, compartmentId);
}
protected GenericProtein createProtein(String proteinId) {
return createProtein(0, 0, 100, 200, proteinId);
}
protected GenericProtein createProtein(double x, double y, double width, double height, String proteinId) {
GenericProtein protein = new GenericProtein("s" + identifierCounter++);
protein.setElementId(proteinId);
protein.setX(x);
protein.setY(y);
protein.setZ(zIndex++);
protein.setWidth(width);
protein.setHeight(height);
return protein;
}
protected Complex createComplex(double x, double y, double width, double height, String complexId) {
Complex complex = new Complex(complexId);
complex.setX(x);
complex.setY(y);
complex.setZ(zIndex++);
complex.setWidth(width);
complex.setHeight(height);
return complex;
}
protected AntisenseRna createAntisenseRna(String aRnaId) {
AntisenseRna antisenseRna = new AntisenseRna(aRnaId);
antisenseRna.setX(1);
antisenseRna.setY(2);
antisenseRna.setZ(zIndex++);
antisenseRna.setWidth(10);
antisenseRna.setHeight(20);
return antisenseRna;
}
protected Chemical createIon(String ionId) {
Chemical ion = new Ion(ionId);
ion.setZ(zIndex++);
return ion;
}
protected Phenotype createPhenotype(String phenotypeId) {
Phenotype phenotype = new Phenotype(phenotypeId);
phenotype.setZ(zIndex++);
return phenotype;
}
protected Rna createRna(String rnaId) {
Rna rna = new Rna(rnaId);
rna.setX(1);
rna.setY(2);
rna.setZ(zIndex++);
rna.setWidth(10);
rna.setHeight(20);
return rna;
}
protected TransportReaction createReaction() {
TransportReaction result = new TransportReaction("re" + identifierCounter++);
result.setZ(zIndex++);
return result;
}
protected ModulationReaction createModulationReaction() {
ModulationReaction result = new ModulationReaction("re" + identifierCounter++);
result.setZ(zIndex++);
return result;
}
}
......@@ -14,14 +14,12 @@ import org.junit.Test;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.OverviewImage;
import lcsb.mapviewer.model.map.OverviewModelLink;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.layout.DataOverlayImageLayer;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.SimpleMolecule;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.persist.PersistTestFunctions;
......@@ -165,14 +163,14 @@ public class ProjectDaoTest extends PersistTestFunctions {
private Model createModel() {
Model model = new ModelFullIndexed(null);
model.addElement(createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "sa2"));
model.addElement(createSpeciesAlias(267.6666666666665, 438.75, 80.0, 40.0, "sa1117"));
model.addElement(createSpeciesAlias(261.6666666666665, 600.75, 92.0, 52.0, "sa1119"));
model.addElement(createSpeciesAlias(203.666666666667, 687.75, 98.0, 58.0, "sa1121"));
model.addElement(createProtein(264.8333333333335, 517.75, 86.0, 46.0, "sa2"));
model.addElement(createProtein(267.6666666666665, 438.75, 80.0, 40.0, "sa1117"));
model.addElement(createProtein(261.6666666666665, 600.75, 92.0, 52.0, "sa1119"));
model.addElement(createProtein(203.666666666667, 687.75, 98.0, 58.0, "sa1121"));
Species alias = createSpeciesAlias(817.714285714286, 287.642857142859, 80.0, 40.0, "sa1422");
Species alias2 = createSpeciesAlias(224.964285714286, 241.392857142859, 80.0, 40.0, "sa1419");
Complex alias3 = createComplexAlias(804.714285714286, 182.642857142859, 112.0, 172.0, "csa152");
Species alias = createProtein(817.714285714286, 287.642857142859, 80.0, 40.0, "sa1422");
Species alias2 = createProtein(224.964285714286, 241.392857142859, 80.0, 40.0, "sa1419");
Complex alias3 = createComplex(804.714285714286, 182.642857142859, 112.0, 172.0, "csa152");
alias3.addSpecies(alias);
alias3.addSpecies(alias2);
alias.setComplex(alias3);
......@@ -182,39 +180,12 @@ public class ProjectDaoTest extends PersistTestFunctions {
model.addElement(alias2);
model.addElement(alias3);
model.addElement(createCompartmentAlias(380.0, 416.0, 1893.0, 1866.0, "ca1"));
model.addElement(createCompartment(380.0, 416.0, 1893.0, 1866.0, "ca1"));
model.setWidth(2000);
model.setHeight(2000);
return model;
}
private Compartment createCompartmentAlias(double x, double y, double width, double height, String aliasId) {
Compartment alias = new Compartment(aliasId);
alias.setX(x);
alias.setY(y);
alias.setWidth(width);
alias.setHeight(height);
return alias;
}
private Species createSpeciesAlias(double x, double y, double width, double height, String aliasId) {
Species alias = new SimpleMolecule(aliasId);
alias.setX(x);
alias.setY(y);
alias.setWidth(width);
alias.setHeight(height);
return alias;
}
private Complex createComplexAlias(double x, double y, double width, double height, String aliasId) {
Complex alias = new Complex(aliasId);
alias.setX(x);
alias.setY(y);
alias.setWidth(width);
alias.setHeight(height);
return alias;
}
@Test
public void testAddGetProjectWithOverviewImage() throws Exception {
try {
......@@ -319,7 +290,8 @@ public class ProjectDaoTest extends PersistTestFunctions {
Project project2 = projectDao.getById(project.getId());
assertEquals(1, project2.getLayouts().size());
assertEquals("tmp", project2.getLayouts().iterator().next().getDataOverlayImageLayers().iterator().next().getDirectory());
assertEquals("tmp",
project2.getLayouts().iterator().next().getDataOverlayImageLayers().iterator().next().getDirectory());
assertEquals("temporary name", project2.getLayouts().iterator().next().getTitle());
project = projectDao.getById(project.getId());
......
......@@ -21,7 +21,6 @@ import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.reaction.Product;
import lcsb.mapviewer.model.map.reaction.Reactant;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.reaction.type.TransportReaction;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Species;
......@@ -102,18 +101,18 @@ public class CommentDaoTest extends PersistTestFunctions {
private Model createModel() {
Model model = new ModelFullIndexed(null);
GenericProtein alias = createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "sa2");
GenericProtein alias = createProtein(264.8333333333335, 517.75, 86.0, 46.0, "sa2");
model.addElement(alias);
alias = createSpeciesAlias(267.6666666666665, 438.75, 80.0, 40.0, "sa1117");
alias = createProtein(267.6666666666665, 438.75, 80.0, 40.0, "sa1117");
model.addElement(alias);
alias = createSpeciesAlias(261.6666666666665, 600.75, 92.0, 52.0, "sa1119");
alias = createProtein(261.6666666666665, 600.75, 92.0, 52.0, "sa1119");
model.addElement(alias);
alias = createSpeciesAlias(203.666666666667, 687.75, 98.0, 58.0, "sa1121");
alias = createProtein(203.666666666667, 687.75, 98.0, 58.0, "sa1121");
model.addElement(alias);
alias = createSpeciesAlias(817.714285714286, 287.642857142859, 80.0, 40.0, "sa1422");
Species alias2 = createSpeciesAlias(224.964285714286, 241.392857142859, 80.0, 40.0, "sa1419");
Complex alias3 = createComplexAlias(804.714285714286, 182.642857142859, 112.0, 172.0, "csa152");
alias = createProtein(817.714285714286, 287.642857142859, 80.0, 40.0, "sa1422");
Species alias2 = createProtein(224.964285714286, 241.392857142859, 80.0, 40.0, "sa1419");
Complex alias3 = createComplex(804.714285714286, 182.642857142859, 112.0, 172.0, "csa152");
alias3.addSpecies(alias);
alias3.addSpecies(alias2);
alias.setComplex(alias3);
......@@ -123,7 +122,7 @@ public class CommentDaoTest extends PersistTestFunctions {
model.addElement(alias2);
model.addElement(alias3);
Compartment cAlias = createCompartmentAlias(380.0, 416.0, 1893.0, 1866.0, "ca1");
Compartment cAlias = createCompartment(380.0, 416.0, 1893.0, 1866.0, "ca1");
model.addElement(cAlias);
model.setWidth(2000);
model.setHeight(2000);
......@@ -135,13 +134,13 @@ public class CommentDaoTest extends PersistTestFunctions {
lr.setColor(Color.YELLOW);
layer.addLayerRect(lr);
Reaction reaction = new TransportReaction();
Reaction reaction = createReaction();
reaction.addProduct(new Product(alias));
reaction.addReactant(new Reactant(alias2));
reaction.setIdReaction("re" + identifierCounter++);
model.addReaction(reaction);
alias = createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "pr1");
alias = createProtein(264.8333333333335, 517.75, 86.0, 46.0, "pr1");
model.addElement(alias);
Residue mr = new Residue();
......@@ -152,34 +151,4 @@ public class CommentDaoTest extends PersistTestFunctions {
return model;
}
private Compartment createCompartmentAlias(double x, double y, double width, double height, String aliasId) {
Compartment alias = new Compartment(aliasId);
alias.setX(x);
alias.setY(y);
alias.setWidth(width);
alias.setHeight(height);
return alias;
}
private GenericProtein createSpeciesAlias(double x, double y, double width, double height, String aliasId) {
GenericProtein alias = new GenericProtein(aliasId);
alias.setName("SNCA");
alias.addMiriamData(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"));
alias.addMiriamData(new MiriamData(MiriamType.HGNC, "11138"));
alias.setX(x);
alias.setY(y);
alias.setWidth(width);
alias.setHeight(height);
return alias;
}
private Complex createComplexAlias(double x, double y, double width, double height, String aliasId) {
Complex alias = new Complex(aliasId);
alias.setX(x);
alias.setY(y);
alias.setWidth(width);
alias.setHeight(height);
return alias;
}
}
......@@ -28,9 +28,7 @@ import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.reaction.Product;
import lcsb.mapviewer.model.map.reaction.Reactant;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.reaction.type.TransportReaction;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.Residue;
......@@ -43,8 +41,6 @@ public class LayoutDaoTest extends PersistTestFunctions {
final static Logger logger = Logger.getLogger(LayoutDaoTest.class);
int identifierCounter = 0;
@Before
public void setUp() throws Exception {
}
......@@ -113,7 +109,7 @@ public class LayoutDaoTest extends PersistTestFunctions {
project.addModel(model);
projectDao.add(project);
assertEquals(0, layoutDao.getCountByUser(user));
assertEquals(0, layoutDao.getLayoutsByProject(project).size());
assertNull(layoutDao.getLayoutByName(project, tempName));
......@@ -125,7 +121,6 @@ public class LayoutDaoTest extends PersistTestFunctions {
project.addLayout(layout);
layoutDao.add(layout);
modelDao.evict(model);
projectDao.evict(project);
layoutDao.evict(layout);
......@@ -151,18 +146,18 @@ public class LayoutDaoTest extends PersistTestFunctions {
private Model createModel() {
Model model = new ModelFullIndexed(null);
Species alias = createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "sa2");
Species alias = createProtein(264.8333333333335, 517.75, 86.0, 46.0, "sa2");
model.addElement(alias);
alias = createSpeciesAlias(267.6666666666665, 438.75, 80.0, 40.0, "sa1117");
alias = createProtein(267.6666666666665, 438.75, 80.0, 40.0, "sa1117");
model.addElement(alias);
alias = createSpeciesAlias(261.6666666666665, 600.75, 92.0, 52.0, "sa1119");
alias = createProtein(261.6666666666665, 600.75, 92.0, 52.0, "sa1119");
model.addElement(alias);
alias = createSpeciesAlias(203.666666666667, 687.75, 98.0, 58.0, "sa1121");
alias = createProtein(203.666666666667, 687.75, 98.0, 58.0, "sa1121");
model.addElement(alias);
alias = createSpeciesAlias(817.714285714286, 287.642857142859, 80.0, 40.0, "sa1422");
Species alias2 = createSpeciesAlias(224.964285714286, 241.392857142859, 80.0, 40.0, "sa1419");
Complex alias3 = createComplexAlias(804.714285714286, 182.642857142859, 112.0, 172.0, "csa152");
alias = createProtein(817.714285714286, 287.642857142859, 80.0, 40.0, "sa1422");
Species alias2 = createProtein(224.964285714286, 241.392857142859, 80.0, 40.0, "sa1419");
Complex alias3 = createComplex(804.714285714286, 182.642857142859, 112.0, 172.0, "csa152");
alias3.addSpecies(alias);
alias3.addSpecies(alias2);
alias.setComplex(alias3);
......@@ -172,7 +167,7 @@ public class LayoutDaoTest extends PersistTestFunctions {
model.addElement(alias2);
model.addElement(alias3);
Compartment cAlias = createCompartmentAlias(380.0, 416.0, 1893.0, 1866.0, "ca1");
Compartment cAlias = createCompartment(380.0, 416.0, 1893.0, 1866.0, "ca1");
model.addElement(cAlias);
model.setWidth(2000);
model.setHeight(2000);
......@@ -184,13 +179,12 @@ public class LayoutDaoTest extends PersistTestFunctions {
lr.setColor(Color.YELLOW);
layer.addLayerRect(lr);
Reaction reaction = new TransportReaction();
Reaction reaction = createReaction();
reaction.addProduct(new Product(alias));
reaction.addReactant(new Reactant(alias2));
reaction.setIdReaction("re" + identifierCounter++);
model.addReaction(reaction);
Protein protein = createSpeciesAlias(264.8333333333335, 517.75, 86.0, 46.0, "pr1");
Protein protein = createProtein(264.8333333333335, 517.75, 86.0, 46.0, "pr1");
model.addElement(protein);
Residue mr = new Residue();
......@@ -201,32 +195,4 @@ public class LayoutDaoTest extends PersistTestFunctions {
return model;
}
private Compartment createCompartmentAlias(double x, double y, double width, double height, String aliasId) {
Compartment alias = new Compartment(aliasId);
alias.setX(x);
alias.setY(y);
alias.setWidth(width);
alias.setHeight(height);
return alias;