Commit 5cc7ecf1 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

unused code removed

parent 33b5a143
......@@ -15,7 +15,6 @@ import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.commands.SemanticZoomLevelMatcher;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidClassException;
......@@ -58,8 +57,6 @@ import lcsb.mapviewer.services.utils.SearchIndexer;
@Service
public class SearchService implements ISearchService {
private SemanticZoomLevelMatcher zoomLevelMatcher = new SemanticZoomLevelMatcher();
/**
* Prefix used in search by name interface to limit results only to species.
*/
......@@ -221,13 +218,13 @@ public class SearchService implements ISearchService {
* @return list of object found for the query string sorted by the score value
*/
protected List<BioEntity> searchByIndexedQuery(Model model, String query, int limit, Boolean perfectMatch,
Class<? extends Element> type) {
Class<? extends Element> type) {
List<BioEntity> result = new ArrayList<>();
if (query.startsWith(REACTION_SEARCH_PREFIX)) {
return getReactionById(model, query.replaceFirst(REACTION_SEARCH_PREFIX, "").toLowerCase());
} else if (query.startsWith(SPECIES_SEARCH_PREFIX)) {
Element element = model.getElementByElementId(query.replaceFirst(SPECIES_SEARCH_PREFIX, ""));
if (element !=null) {
if (element != null) {
result.add(element);
}
} else if (query.startsWith(ELEMENT_SEARCH_PREFIX)) {
......@@ -358,114 +355,9 @@ public class SearchService implements ISearchService {
return result;
}
@Override
public List<BioEntity> searchByCoordinates(CoordinatesSearchParams params) {
List<Object> results = new ArrayList<Object>();
Set<Element> aliases = params.getModel().getElements();
Point2D point = new Point2D.Double(params.getX(), params.getY());
for (Element alias : aliases) {
if (alias instanceof Species) {
if (alias.contains(point)) {
if (isVisible(alias, params)) {
results.add(alias);
}
}
}
}
List<BioEntity> result = new ArrayList<>();
double dist = params.getDistance();
if (results.size() == 0) {
Reaction r = null;
Set<Reaction> reactions = params.getModel().getReactions();
for (Reaction reaction : reactions) {
double newDist = reaction.getDistanceFromPoint(point);
if (newDist < dist) {
if (isVisible(reaction, params)) {
r = reaction;
dist = reaction.getDistanceFromPoint(point);
}
}
}
if (r != null) {
result.addAll(reactionToResultList(r));
return result;
}
}
if (results.size() > 1) {
Element alias = (Element) results.get(0);
for (Object obj : results) {
if (((Element) (obj)).getSize() < alias.getSize()) {
alias = (Element) obj;
}
}
results.clear();
results.add(alias);
}
if (results.size() == 0) {
return result;
} else {
Object obj = results.get(0);
if (obj instanceof Element) {
result.add((BioEntity) obj);
return result;
} else if (obj instanceof Reaction) {
result.addAll(reactionToResultList((Reaction) obj));
return result;
} else {
throw new InvalidStateException("Unknown class type: " + obj.getClass());
}
}
}
/**
* Check if reaction is visible for the user. Reaction is visible when at least
* one node of the reaction is visible.
*
* @param reaction
* which reaction is tested
* @param params
* params that determines the client search environment (zoom level,
* type of the layout)
* @return <code>true</code> if reaction is visible for the user,
* <code>false</code> otherwise
*/
private boolean isVisible(Reaction reaction, CoordinatesSearchParams params) {
if (params.getLevel() == null) {
return true;
}
for (ReactionNode node : reaction.getReactionNodes()) {
if (isVisible(node.getElement(), params)) {
return true;
}
}
return false;
}
/**
* Checks if alias is visible for the user. Alias is invisible when the search
* is performed on the hierarchical layout and the alias is hidden by the
* complex or compartment.
*
* @param alias
* alias to be checked for visibility
* @param params
* that determines the client search environment (zoom level, type of
* the layout)
* @return <code>true</code> if alias is visible for the user,
* <code>false</code> otherwise
*/
private boolean isVisible(Element alias, CoordinatesSearchParams params) {
if (params.getLevel() == null) {
return true;
}
return zoomLevelMatcher.isVisible(params.getLevel(), alias.getVisibilityLevel());
}
@Override
public List<BioEntity> searchByQuery(Model model, String query, int limit, Boolean perfectMatch,
String ipAddress) {
String ipAddress) {
query = query.toLowerCase();
if (query == null) {
throw new InvalidArgumentException("Invalid query: null");
......@@ -552,7 +444,7 @@ public class SearchService implements ISearchService {
@Override
public List<BioEntity> getClosestElements(Model model, Point2D point, int numberOfElements, boolean perfectHit,
Collection<String> types) {
Collection<String> types) {
List<BioEntity> result = new ArrayList<>();
// probably this could be improved algorithmitically, right now all objects
......
......@@ -4,8 +4,6 @@ import java.awt.geom.Point2D;
import java.util.Collection;
import java.util.List;
import org.apache.log4j.Logger;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.model.Model;
......@@ -16,172 +14,6 @@ import lcsb.mapviewer.model.map.model.Model;
*
*/
public interface ISearchService {
/**
* Parameters of search objects on the map using coordinates. It's possible to
* add also information about nested model and level at which searching is
* performed in the hierarchical view. More information about hierarchical view
* can be found in the definition of
* {@link lcsb.mapviewer.converter.graphics.AbstractImageGenerator
* AbstractImageGenerator}.
*
* @author Piotr Gawron
*
*/
class CoordinatesSearchParams {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private final Logger logger = Logger.getLogger(CoordinatesSearchParams.class);
/**
* Model where we perform search.
*/
private Model model = null;
/**
* X coordinate of the search event.
*/
private double x = 0;
/**
* Y coordinate of the search event.
*/
private double y = 0;
/**
* Maximum distance between object that could be found and point that is valid.
*/
private double distance = 0;
/**
* Level at which the search is performed. It's used during determining if the
* object is visible in hierarchical view.
*/
private Integer level = null;
/**
* @return the model
* @see #model
*/
public Model getModel() {
return model;
}
/**
* @param model
* the model to set
* @return object with all parameters
* @see #model
*/
public CoordinatesSearchParams model(Model model) {
this.model = model;
return this;
}
/**
* @param point
* the coordinates to set
* @return object with all parameters
* @see #model
*/
public CoordinatesSearchParams point(Point2D point) {
this.x = point.getX();
this.y = point.getY();
return this;
}
/**
* @return the x
* @see #x
*/
public double getX() {
return x;
}
/**
* @param x
* the x to set
* @return object with all parameters
* @see #x
*/
public CoordinatesSearchParams x(double x) {
this.x = x;
return this;
}
/**
* @return the y
* @see #y
*/
public double getY() {
return y;
}
/**
* @param y
* the y to set
* @return object with all parameters
* @see #y
*/
public CoordinatesSearchParams y(double y) {
this.y = y;
return this;
}
/**
* @return the distance
* @see #distance
*/
public double getDistance() {
return distance;
}
/**
* @param distance
* the distance to set
* @return object with all parameters
* @see #distance
*/
public CoordinatesSearchParams distance(double distance) {
this.distance = distance;
return this;
}
/**
* @param level
* the level to set
* @return object with all parameters
* @see #level
*/
public CoordinatesSearchParams level(Integer level) {
this.level = level;
return this;
}
/**
* @return the level
* @see #level
*/
public Integer getLevel() {
return level;
}
}
/**
* Search the element on the map using coordinates. It is also possible to
* provide information about layout (if it's nested or not) and hierarchical
* level.
*
* @param params
* set of search params. More information can be found here:
* {@link CoordinatesSearchParams}
* @return object that match best the search criteria. If such object doesn't
* exist then <code>null</code> is returned.
*/
List<BioEntity> searchByCoordinates(CoordinatesSearchParams params);
/**
* Search for elements on the map by query. Returns many possibilities from best
......
......@@ -42,7 +42,6 @@ import lcsb.mapviewer.model.map.species.SimpleMolecule;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.Unknown;
import lcsb.mapviewer.services.ServiceTestFunctions;
import lcsb.mapviewer.services.interfaces.ISearchService.CoordinatesSearchParams;
import lcsb.mapviewer.services.utils.SearchIndexer;
public class SearchServiceTest extends ServiceTestFunctions {
......@@ -53,6 +52,8 @@ public class SearchServiceTest extends ServiceTestFunctions {
Map<Class<?>, String> speciesSearchPrefix = new HashMap<Class<?>, String>();
Map<String, Class<?>> speciesSearchReversePrefix = new HashMap<String, Class<?>>();
int elementCounter = 0;
@Before
public void setUp() throws Exception {
addSearchPrefix("complex", Complex.class);
......@@ -329,11 +330,7 @@ public class SearchServiceTest extends ServiceTestFunctions {
public void testSearchClosest2() throws Exception {
try {
Model model = new ModelFullIndexed(null);
GenericProtein protein1 = new GenericProtein("s1");
protein1.setWidth(20);
protein1.setHeight(20);
protein1.setX(5);
protein1.setY(5);
GenericProtein protein1 = createProtein();
model.addElement(protein1);
GenericProtein protein2 = new GenericProtein("s2");
protein2.setWidth(10);
......@@ -352,12 +349,14 @@ public class SearchServiceTest extends ServiceTestFunctions {
new ArrayList<>());
assertNotNull(elements);
assertEquals(3, elements.size());
BioEntity sAlias = elements.get(0);
assertEquals("s2", sAlias.getName());
BioEntity reaction = elements.get(1);
assertEquals("s1", reaction.getName());
sAlias = elements.get(2);
assertEquals("s3", sAlias.getName());
BioEntity element0 = elements.get(0);
assertEquals("s2", element0.getName());
BioEntity element1 = elements.get(1);
assertEquals(protein1.getName(), element1.getName());
BioEntity element2 = elements.get(2);
assertEquals("s3", element2.getName());
} catch (Exception e) {
e.printStackTrace();
......@@ -365,6 +364,15 @@ public class SearchServiceTest extends ServiceTestFunctions {
}
}
private GenericProtein createProtein() {
GenericProtein protein1 = new GenericProtein("s" + elementCounter++);
protein1.setWidth(20);
protein1.setHeight(20);
protein1.setX(5);
protein1.setY(5);
return protein1;
}
@Test
public void testSearchClosestWithEmptyModel() throws Exception {
try {
......@@ -476,63 +484,6 @@ public class SearchServiceTest extends ServiceTestFunctions {
}
@Test
public void testSearchByCoordCompartment() throws Exception {
try {
Model model = getModelForFile("testFiles/graph_path_example3.xml", true);
// we search in non-nested model
List<BioEntity> res = searchService.searchByCoordinates(new CoordinatesSearchParams().model(model).x(50).y(50));
assertNotNull(res);
assertEquals(0, res.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSearchByCoordReaction() throws Exception {
try {
Model model = getModelForFile("testFiles/graph_path_example3.xml", true);
// find compartment
List<BioEntity> res = searchService.searchByCoordinates(new CoordinatesSearchParams().model(model));
// reaction is too far
assertEquals(0, res.size());
res = searchService.searchByCoordinates(new CoordinatesSearchParams().model(model).distance(1000));
assertEquals(3, res.size());
assertTrue(res.get(0) instanceof Reaction);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSearchByCoordAlias() throws Exception {
try {
Model model = getModelForFile("testFiles/graph_path_example3.xml", true);
List<BioEntity> res = searchService.searchByCoordinates(new CoordinatesSearchParams().model(model).x(60).y(60));
assertNotNull(res);
assertTrue(res.size() > 0);
assertTrue(res.get(0) instanceof Species);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetMiriamTypeForQuery() throws Exception {
try {
......
Markdown is supported
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