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

when removing data overlay update sorting order

parent bf617223
......@@ -3,6 +3,7 @@ package lcsb.mapviewer.api.projects.overlays;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -227,8 +228,13 @@ public class OverlayRestImpl extends BaseRestImpl {
public Map<String, Object> removeOverlay(String projectId, Integer overlayId)
throws QueryException, IOException {
Layout layout = getOverlay(projectId, overlayId);
User owner = layout.getCreator();
Project project = layout.getProject();
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);
for (int i = 0; i < overlays.size(); i++) {
Layout overlay = overlays.get(i);
......
......@@ -1206,4 +1206,33 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
.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());
}
}
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