Commit 8579e132 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

submap id is taken into consideration when searching map

parent 570a413a
......@@ -58,7 +58,7 @@ public class BioEntitiesController extends BaseController {
if (count.trim().isEmpty()) {
count = "100";
}
return bioEntitiesRestImpl.getElementsByQuery(projectId, query, Integer.valueOf(count),
return bioEntitiesRestImpl.getElementsByQuery(projectId, query, modelId, Integer.valueOf(count),
perfectMatch);
} else {
return new ArrayList<>();
......
......@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.ObjectNotFoundException;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.services.interfaces.ISearchService;
......@@ -32,13 +33,18 @@ public class BioEntitiesRestImpl extends BaseRestImpl {
}
public List<Map<String, Object>> getClosestElementsByCoordinates(
String projectId, String modelId, Point2D coordinates, Integer count, String perfectMatch, String type) {
String projectId, String modelId, Point2D coordinates, Integer count, String perfectMatch, String type)
throws ObjectNotFoundException {
List<Map<String, Object>> resultMap = new ArrayList<>();
Model model = getModelService().getLastModelByProjectId(projectId);
Model submodel = model.getSubmodelById(modelId);
if (submodel == null) {
throw new ObjectNotFoundException("Model with given id doesn't exist");
}
Set<String> types = new LinkedHashSet<>();
if (!type.isEmpty()) {
for (String str : type.split(",")) {
......@@ -55,11 +61,17 @@ public class BioEntitiesRestImpl extends BaseRestImpl {
return resultMap;
}
public List<Map<String, Object>> getElementsByQuery(String projectId, String query,
Integer maxElements, String perfectMatch) {
public List<Map<String, Object>> getElementsByQuery(String projectId, String query, String modelId,
Integer maxElements, String perfectMatch) throws ObjectNotFoundException {
List<Map<String, Object>> resultMap = new ArrayList<>();
Model model = getModelService().getLastModelByProjectId(projectId);
if (!modelId.equals("*")) {
model = model.getSubmodelById(modelId);
}
if (model == null) {
throw new ObjectNotFoundException("Model with given id doesn't exist");
}
boolean match = perfectMatch.equals("true");
List<BioEntity> elements = searchService.searchByQuery(model, query, maxElements, match);
......
......@@ -322,7 +322,7 @@ public class SearchService implements ISearchService {
Collection<String> types) {
List<BioEntity> result = new ArrayList<>();
// probably this could be improved algorithmitically, right now all objects
// probably this could be improved algorithmically, right now all objects
// are sorted by distance, and numberOfElements closest are chosen as a list
// of results
List<DistanceToObject> tmpList = new ArrayList<>();
......
......@@ -88,6 +88,42 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
.andExpect(status().is2xxSuccessful());
}
@Test
public void testSearchBioEntitiesByCoordinatesWithInvalidModelId() throws Exception {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get(
"/projects/" + TEST_PROJECT + "/models/-1/bioEntities:search?coordinates=104.36,182.81")
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testSearchBioEntitiesWithInvalidModelId() throws Exception {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get(
"/projects/" + TEST_PROJECT + "/models/-1/bioEntities:search?query=s1")
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testSearchBioEntitiesOnEverySubmap() throws Exception {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get(
"/projects/" + TEST_PROJECT + "/models/*/bioEntities:search?query=s1")
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
}
@Test
public void testGetMapById() throws Exception {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
......
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