Commit 75be6bed authored by Piotr Gawron's avatar Piotr Gawron
Browse files

filtering by complex id implemented

parent 2ac3f650
......@@ -33,7 +33,9 @@ import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.persist.dao.BaseDao;
@Repository
......@@ -272,6 +274,30 @@ public class ElementDao extends BaseDao<Element, ElementProperty> {
orPredicates.add(builder.equal(compartmentJoin.get("id"), object));
}
predicates.add(builder.or(orPredicates.toArray(new Predicate[] {})));
} else if (key.equals(ElementProperty.COMPLEX_ID)) {
Object value = filterOptions.get(key);
List<?> values = (List<?>) value;
List<Predicate> orPredicates = new ArrayList<>();
Join<Species, Complex> complexJoin = builder.treat(root, Species.class).join("complex");
for (Object object : values) {
orPredicates.add(builder.equal(complexJoin.get("id"), object));
}
predicates.add(builder.or(orPredicates.toArray(new Predicate[] {})));
} else if (key.equals(ElementProperty.MAP_ID)) {
Object value = filterOptions.get(key);
List<?> values = (List<?>) value;
List<Predicate> orPredicates = new ArrayList<>();
Join<Element, ModelData> complexJoin = root.join("model");
for (Object object : values) {
orPredicates.add(builder.equal(complexJoin.get("id"), object));
}
predicates.add(builder.or(orPredicates.toArray(new Predicate[] {})));
} else if (key.equals(ElementProperty.NAME)) {
Object value = filterOptions.get(key);
......
......@@ -104,6 +104,10 @@ public class PersistTestFunctionsNoTransaction extends TestUtils {
return complex;
}
protected Complex createComplex() {
return createComplex(10, 20, 100, 200, "comp" + (identifierCounter++));
}
protected AntisenseRna createAntisenseRna(final String antiseneseRnaId) {
AntisenseRna antisenseRna = new AntisenseRna(antiseneseRnaId);
assignCoordinates(1, 2, 10, 20, antisenseRna);
......
......@@ -6,10 +6,12 @@ import org.junit.runners.Suite.SuiteClasses;
import lcsb.mapviewer.persist.dao.map.kinetics.AllKineticsTests;
import lcsb.mapviewer.persist.dao.map.layout.AllLayoutTests;
import lcsb.mapviewer.persist.dao.map.species.AllSpeciesTests;
@RunWith(Suite.class)
@SuiteClasses({
AllKineticsTests.class,
AllSpeciesTests.class,
AuthorDaoTest.class,
AllLayoutTests.class,
CommentDaoTest.class,
......
......@@ -4,10 +4,8 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import lcsb.mapviewer.persist.dao.map.layout.alias.AllAliasTests;
@RunWith(Suite.class)
@SuiteClasses({ AllAliasTests.class,
@SuiteClasses({
ReferenceGenomeDaoTest.class,
ReferenceGenomeGeneMappingDaoTest.class,
})
......
package lcsb.mapviewer.persist.dao.map.layout.alias;
package lcsb.mapviewer.persist.dao.map.species;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
......@@ -10,6 +10,6 @@ import org.junit.runners.Suite.SuiteClasses;
ElementDaoGetByQueryTest.class,
RnaTest.class,
})
public class AllAliasTests {
public class AllSpeciesTests {
}
package lcsb.mapviewer.persist.dao.map.layout.alias;
package lcsb.mapviewer.persist.dao.map.species;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
......
package lcsb.mapviewer.persist.dao.map.layout.alias;
package lcsb.mapviewer.persist.dao.map.species;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
......
package lcsb.mapviewer.persist.dao.map.layout.alias;
package lcsb.mapviewer.persist.dao.map.species;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
......@@ -12,6 +12,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -42,11 +46,10 @@ import lcsb.mapviewer.model.map.species.field.ModificationSite;
import lcsb.mapviewer.model.map.species.field.Residue;
import lcsb.mapviewer.model.map.species.field.Structure;
import lcsb.mapviewer.model.map.species.field.UniprotRecord;
import lcsb.mapviewer.persist.DbUtils;
import lcsb.mapviewer.persist.PersistTestFunctions;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.persist.dao.map.ModelDao;
import lcsb.mapviewer.persist.dao.map.species.ElementDao;
import lcsb.mapviewer.persist.dao.map.species.ElementProperty;
public class ElementDaoTest extends PersistTestFunctions {
......@@ -56,6 +59,9 @@ public class ElementDaoTest extends PersistTestFunctions {
@Autowired
private ModelDao modelDao;
@Autowired
private DbUtils dbUtils;
@Autowired
private ProjectDao projectDao;
......@@ -898,13 +904,41 @@ public class ElementDaoTest extends PersistTestFunctions {
}
@Test
public void testGetAllByEmptyFilter() throws Exception {
public void testFilterByComplex() throws Exception {
GenericProtein protein = createProtein();
Complex parent = createComplex();
protein.setComplex(parent);
elementDao.add(protein);
elementDao.add(createProtein());
elementDao.add(createCompartment());
Map<ElementProperty, Object> properties = new HashMap<>();
properties.put(ElementProperty.COMPLEX_ID, Arrays.asList(parent.getId()));
assertEquals(1, elementDao.getAll(properties, PageRequest.of(0, 10)).getNumberOfElements());
}
@Test
public void testGetPredicate() throws Exception {
CriteriaBuilder builder = dbUtils.getSessionFactory().getCurrentSession().getCriteriaBuilder();
CriteriaQuery<Element> criteria = builder.createQuery(Element.class);
Root<Element> root = criteria.from(Element.class);
for (ElementProperty property : ElementProperty.values()) {
Map<ElementProperty, Object> properties = new HashMap<>();
properties.put(property, new ArrayList<>());
List<Object> list = new ArrayList<>();
assertEquals(0, elementDao.getAll(properties, PageRequest.of(0, 10)).getNumberOfElements());
if (property == ElementProperty.PERFECT_TEXT || property == ElementProperty.TEXT) {
list.add("");
} else if (property == ElementProperty.SUBMAP_CONNECTION) {
list.add(Boolean.TRUE);
}
Map<ElementProperty, Object> properties = new HashMap<>();
properties.put(property, list);
assertNotNull(elementDao.createPredicate(properties, root, criteria));
}
}
......
package lcsb.mapviewer.persist.dao.map.layout.alias;
package lcsb.mapviewer.persist.dao.map.species;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment