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

provide info about deprecated columns in API

parent 9b1ceb38
......@@ -12,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.api.*;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.common.geometry.ColorParser;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.cache.FileEntry;
......@@ -26,6 +27,8 @@ import lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao;
import lcsb.mapviewer.persist.dao.map.LayoutDao;
import lcsb.mapviewer.services.interfaces.ILayoutService;
import lcsb.mapviewer.services.interfaces.ILayoutService.CreateLayoutParams;
import lcsb.mapviewer.services.utils.ColorSchemaReader;
import lcsb.mapviewer.services.utils.data.ColorSchemaColumn;
@Transactional
@Service
......@@ -78,6 +81,8 @@ public class OverlayRestImpl extends BaseRestImpl {
result.put("description", overlay.getDescription());
result.put("publicOverlay", overlay.isPublicLayout());
result.put("defaultOverlay", overlay.isDefaultOverlay());
result.put("deprecatedColumns", getDeprecatedColumns(overlay));
result.put("googleLicenseConsent", overlay.isGoogleLicenseConsent());
List<Map<String, Object>> images = new ArrayList<>();
List<DataOverlayImageLayer> imageList = new ArrayList<>(overlay.getDataOverlayImageLayers());
......@@ -97,6 +102,18 @@ public class OverlayRestImpl extends BaseRestImpl {
return result;
}
private String getDeprecatedColumns(Layout overlay) {
try {
String result = "";
for (ColorSchemaColumn column : new ColorSchemaReader().getDeprecatedColumns(overlay)) {
result += column.name() + ",";
}
return result;
} catch (IOException | InvalidColorSchemaException e) {
throw new InvalidStateException(e);
}
}
public List<Map<String, Object>> getOverlayElements(String projectId, int overlayId, String columns)
throws QueryException {
......
package lcsb.mapviewer.services.utils;
import java.awt.*;
import java.awt.Color;
import java.io.*;
import java.lang.reflect.Field;
import java.util.*;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
......@@ -12,8 +11,7 @@ import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.annotation.services.MiriamConnector;
import lcsb.mapviewer.common.*;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.common.exception.*;
import lcsb.mapviewer.common.geometry.ColorParser;
import lcsb.mapviewer.converter.model.celldesigner.species.SpeciesMapping;
import lcsb.mapviewer.converter.zip.ZipEntryFileFactory;
......@@ -808,4 +806,32 @@ public class ColorSchemaReader {
}
return readColorSchema(new ByteArrayInputStream(inputData), params);
}
public List<ColorSchemaColumn> getDeprecatedColumns(Layout overlay)
throws IOException, InvalidColorSchemaException {
List<ColorSchemaColumn> result = new ArrayList<>();
BufferedReader br = new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(overlay.getInputData().getFileContent())));
String line = br.readLine();
while (line != null && line.startsWith("#")) {
line = br.readLine();
}
String[] columns = line.split("\t");
Map<ColorSchemaColumn, Integer> schemaColumns = new HashMap<>();
parseColumns(columns, schemaColumns, ColorSchemaType.GENERIC);
for (ColorSchemaColumn column : schemaColumns.keySet()) {
try {
Field f = ColorSchemaColumn.class.getField(column.name());
if (column.getDepractedColumnName() != null || f.isAnnotationPresent(Deprecated.class)) {
result.add(column);
}
} catch (NoSuchFieldException | SecurityException e) {
throw new InvalidStateException(e);
}
}
return result;
}
}
package lcsb.mapviewer.web;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
......@@ -34,6 +34,7 @@ import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.map.LayoutDao;
import lcsb.mapviewer.services.interfaces.IModelService;
import lcsb.mapviewer.services.interfaces.IUserService;
import lcsb.mapviewer.services.utils.data.ColorSchemaColumn;
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
......@@ -422,9 +423,8 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
.getAsJsonArray().size());
}
private Layout createOverlay(User admin) {
private Layout createOverlay(User admin, String content) {
UploadedFileEntry file = new UploadedFileEntry();
String content = "elementIdentifier\tvalue\n\t-1";
file.setFileContent(content.getBytes());
file.setLength(content.getBytes().length);
......@@ -436,6 +436,10 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
return overlay;
}
private Layout createOverlay(User admin) {
return createOverlay(admin, "elementIdentifier\tvalue\n\t-1");
}
@Test
public void testGetReactionsForOverlay() throws Exception {
User admin = createAdmin(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
......@@ -1028,4 +1032,31 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
.andExpect(status().is2xxSuccessful());
}
@Test
public void testDeprecatedOverlayInformation() throws Exception {
createAdmin(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
Layout overlay = createOverlay(null,
"elementIdentifier\t" + ColorSchemaColumn.REACTION_IDENTIFIER + "\tvalue\n\t\t-1");
overlay.setPublicLayout(true);
layoutDao.update(overlay);
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
RequestBuilder request = get(
"/projects/" + TEST_PROJECT + "/overlays/" + overlay.getId() + "/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
String response = mockMvc.perform(request)
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse().getContentAsString();
String deprecatedColumns = new JsonParser()
.parse(response)
.getAsJsonObject().get("deprecatedColumns").getAsString();
assertNotNull(deprecatedColumns);
assertFalse(deprecatedColumns.isEmpty());
}
}
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