Commit 19c86f33 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '860-api-call-searchbyquery-ignores-modelid' into 'master'

Resolve "API call: searchByQuery ignores modelId"

Closes #860

See merge request !873
parents 0d0d46fb 09b6d0b3
Pipeline #12711 passed with stage
in 13 minutes and 51 seconds
minerva (14.0.0~alpha.1) unstable; urgency=low
* Small improvement: debian package can be installed on debian:buster (#879)
* Feature removal: support for tomcat7 removed (#828)
* Small improvement: debian package can be installed on debian:buster (#879)
* Bug fix: REST API bioEntities:search method didn't limit results to the
submodel id (#880)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 12 Aug 2019 10:00:00 +0200
......
......@@ -52,13 +52,13 @@ AbstractDbPanel.prototype._createEventHandlers = function () {
busyImage.show();
return self.searchByQuery().finally(function () {
busyImage.hide();
});
}).catch(GuiConnector.alert);
};
searchButton.onclick = searchByQuery;
searchInput.onkeypress = function (event) {
if (event.keyCode === 13) {
return searchByQuery().then(null, GuiConnector.alert);
return searchByQuery();
}
};
......
......@@ -204,22 +204,6 @@ describe('ElementExportPanel', function () {
});
});
it('download file', function () {
var exportObject;
var project;
return ServerConnector.getProject().then(function (result) {
project = result;
exportObject = createExportPanel(project);
return exportObject.init();
}).then(function () {
$("input[name='ALL']", $(testDiv)).each(function (index, element) {
$(element).prop("checked", true);
});
var element = $("[name='downloadButton']", $(testDiv))[0];
return element.onclick();
});
});
describe('createResponseRow', function () {
it('description with new line', function () {
var exportObject = createExportPanel(helper.createProject());
......
......@@ -21,7 +21,7 @@ describe('NetworkExportPanel', function () {
});
}
it('download file', function () {
it('createResponseString', function () {
var exportObject;
var project;
return ServerConnector.getProject().then(function (result) {
......@@ -32,9 +32,8 @@ describe('NetworkExportPanel', function () {
$("input[name='ALL']", $(testDiv)).each(function (index, element) {
$(element).prop("checked", true);
});
var element = $("[name='downloadButton']", $(testDiv))[0];
assert.equal(0, logger.getWarnings().length);
return element.onclick();
return exportObject.createResponseString();
});
});
......
......@@ -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