Commit df8cc024 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '918-number-of-user-provided-data-overlays-is-not-increasing-correctly' into 'master'

Resolve "number of user provided data overlays is not increasing correctly"

Closes #918

See merge request !907
parents 0fbe97da 2c2e3fde
Pipeline #13177 passed with stage
in 13 minutes and 10 seconds
...@@ -35,6 +35,8 @@ minerva (14.0.0~beta.0) unstable; urgency=low ...@@ -35,6 +35,8 @@ minerva (14.0.0~beta.0) unstable; urgency=low
case the type was not specified in the input file (#906) case the type was not specified in the input file (#906)
* Bug fix: list of types when copying from annotators contains only types * Bug fix: list of types when copying from annotators contains only types
that are selectable in the dialog (#911) that are selectable in the dialog (#911)
* Bug fix: remove of data overlay didn't update numbering of data overlays
that are still in the system (#918)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 21 Aug 2019 21:00:00 +0200 -- Piotr Gawron <piotr.gawron@uni.lu> Mon, 21 Aug 2019 21:00:00 +0200
......
...@@ -3,6 +3,7 @@ package lcsb.mapviewer.api.projects.overlays; ...@@ -3,6 +3,7 @@ package lcsb.mapviewer.api.projects.overlays;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -227,8 +228,13 @@ public class OverlayRestImpl extends BaseRestImpl { ...@@ -227,8 +228,13 @@ public class OverlayRestImpl extends BaseRestImpl {
public Map<String, Object> removeOverlay(String projectId, Integer overlayId) public Map<String, Object> removeOverlay(String projectId, Integer overlayId)
throws QueryException, IOException { throws QueryException, IOException {
Layout layout = getOverlay(projectId, overlayId); Layout layout = getOverlay(projectId, overlayId);
User owner = layout.getCreator();
Project project = layout.getProject();
layoutService.removeLayout(layout, null); layoutService.removeLayout(layout, null);
List<Layout> overlays = layoutService.getLayoutsByProject(layout.getProject());
List<Layout> overlays = layoutService.getLayoutsByProject(project).stream()
.filter(lay -> lay.getCreator() == owner).collect(Collectors.toList());
overlays.sort(Layout.ORDER_COMPARATOR); overlays.sort(Layout.ORDER_COMPARATOR);
for (int i = 0; i < overlays.size(); i++) { for (int i = 0; i < overlays.size(); i++) {
Layout overlay = overlays.get(i); Layout overlay = overlays.get(i);
......
...@@ -460,9 +460,6 @@ public class LayoutService implements ILayoutService { ...@@ -460,9 +460,6 @@ public class LayoutService implements ILayoutService {
@Override @Override
public List<Layout> getLayoutsByProject(Project project) { public List<Layout> getLayoutsByProject(Project project) {
List<Layout> result = new ArrayList<>(); List<Layout> result = new ArrayList<>();
if (project == null) {
return result;
}
List<Layout> overlays = layoutDao.getLayoutsByProject(project); List<Layout> overlays = layoutDao.getLayoutsByProject(project);
result.addAll(overlays); result.addAll(overlays);
result.sort(Layout.ID_COMPARATOR); result.sort(Layout.ID_COMPARATOR);
......
...@@ -1206,4 +1206,60 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest ...@@ -1206,4 +1206,60 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
.andExpect(status().isNotFound()); .andExpect(status().isNotFound());
} }
@Test
public void testOrderAfterRemoveOverlay() throws Exception {
createAdmin(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
User user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD);
Layout overlay1 = createOverlay(user);
overlay1.setOrderIndex(1);
Layout overlay2 = createOverlay(user);
overlay2.setOrderIndex(2);
Layout overlay3 = createOverlay(user);
overlay3.setOrderIndex(3);
layoutDao.update(overlay1);
layoutDao.update(overlay2);
layoutDao.update(overlay3);
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/overlays/" + overlay2.getId())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
assertEquals(1, overlay1.getOrderIndex());
assertEquals(2, overlay3.getOrderIndex());
}
@Test
public void testOrderAfterRemoveOverlayForPublicOverlay() throws Exception {
createAdmin(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
Layout overlay1 = createOverlay(null);
overlay1.setOrderIndex(1);
Layout overlay2 = createOverlay(null);
overlay2.setOrderIndex(2);
Layout overlay3 = createOverlay(null);
overlay3.setOrderIndex(3);
layoutDao.update(overlay1);
layoutDao.update(overlay2);
layoutDao.update(overlay3);
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/overlays/" + overlay2.getId())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
assertEquals(1, overlay1.getOrderIndex());
assertEquals(2, overlay3.getOrderIndex());
}
} }
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