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

ColorSchemaType is obligatory

parent f663508f
......@@ -12,10 +12,12 @@ import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.TextFileUtils;
import lcsb.mapviewer.common.exception.*;
import lcsb.mapviewer.common.exception.InvalidClassException;
import lcsb.mapviewer.converter.zip.*;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.layout.ColorSchemaType;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.*;
import lcsb.mapviewer.model.map.reaction.Reaction;
......@@ -310,6 +312,18 @@ public class ComplexZipConverter {
fileEntry.setFileContent(IOUtils.toByteArray(zipFile.getInputStream(entry)));
fileEntry.setOriginalFileName(entry.getName());
fileEntry.setLength(fileEntry.getFileContent().length);
Map<String, String> parameters = TextFileUtils.getHeaderParametersFromFile(zipFile.getInputStream(entry));
ColorSchemaType colorSchemaType = null;
String type = parameters.get(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE);
if (type != null) {
colorSchemaType = ColorSchemaType.valueOf(type);
}
if (colorSchemaType == null) {
colorSchemaType = ColorSchemaType.GENERIC;
}
layout.setColorSchemaType(colorSchemaType);
layout.setInputData(fileEntry);
layout.setPublicLayout(true);
layout.setTitle(layoutEntry.getName());
......
package lcsb.mapviewer.services.impl;
import java.awt.*;
import java.awt.Color;
import java.io.IOException;
import java.util.*;
import java.util.Comparator;
import java.util.List;
import javax.mail.MessagingException;
......@@ -153,6 +152,17 @@ public class LayoutService implements ILayoutService {
public Layout createLayout(final CreateLayoutParams params) throws IOException, InvalidColorSchemaException {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> parameters = TextFileUtils.getHeaderParametersFromFile(params.getColorInputStream());
ColorSchemaType colorSchemaType = params.getColorSchemaType();
if (colorSchemaType == null) {
String type = parameters.get(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE);
if (type != null) {
colorSchemaType = ColorSchemaType.valueOf(type);
}
}
if (colorSchemaType == null) {
colorSchemaType = ColorSchemaType.GENERIC;
}
if (parameters.get(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE) == null && params.getColorSchemaType() != null) {
parameters.put(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE, params.getColorSchemaType().name());
}
......@@ -171,7 +181,7 @@ public class LayoutService implements ILayoutService {
layoutDao.flush();
Layout topLayout = new Layout(params.getName(), false);
topLayout.setColorSchemaType(params.getColorSchemaType());
topLayout.setColorSchemaType(colorSchemaType);
if (params.getUser() == null) {
topLayout.setPublicLayout(true);
} else {
......
......@@ -773,6 +773,7 @@ public class ProjectService implements IProjectService {
for (BuildInLayout buildInLayout : buildInLayouts) {
int submodelId = 0;
Layout topLayout = new Layout(buildInLayout.getTitle(), true);
topLayout.setColorSchemaType(ColorSchemaType.GENERIC);
topLayout.setStatus(LayoutStatus.NA);
topLayout.setProgress(0.0);
topLayout.setHierarchicalView(buildInLayout.isNested());
......@@ -787,6 +788,7 @@ public class ProjectService implements IProjectService {
if (params.isSemanticZoomContainsMultipleLayouts() && buildInLayout == BuildInLayout.NESTED) {
for (int i = 0; i <= topModel.getZoomLevels(); i++) {
Layout semanticOverlay = new Layout(buildInLayout.getTitle() + "-" + i, true);
semanticOverlay.setColorSchemaType(ColorSchemaType.GENERIC);
String directory = params.getProjectDir() + "/" + buildInLayout.getDirectorySuffix() + "-" + i + "-"
+ topModel.getId() + "/";
......
......@@ -31,6 +31,7 @@ import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectStatus;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.layout.ColorSchemaType;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.map.reaction.*;
......@@ -302,6 +303,7 @@ abstract public class ControllerIntegrationTest {
file.setLength(content.getBytes().length);
Layout overlay = new Layout();
overlay.setColorSchemaType(ColorSchemaType.GENERIC);
overlay.setInputData(file);
overlay.setProject(project);
overlay.setCreator(admin);
......
......@@ -83,15 +83,9 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
User user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD);
Layout layout = new Layout();
layout.setCreator(user);
layout.setProject(project);
layoutDao.add(layout);
createOverlay(project, user);
Layout curatorLayout = new Layout();
curatorLayout.setCreator(curator);
curatorLayout.setProject(project);
layoutDao.add(curatorLayout);
createOverlay(project, curator);
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
......@@ -112,8 +106,7 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
public void testListPublicOverlaysOverlaysWhenCreatorEmpty() throws Exception {
createAdmin(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
Layout layout = new Layout();
layout.setProject(project);
Layout layout= createOverlay(project, null);
layout.setPublicLayout(true);
layoutDao.add(layout);
......@@ -136,8 +129,7 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
public void testListNonPublicOverlaysOverlaysWhenCreatorEmpty() throws Exception {
createAdmin(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
Layout layout = new Layout();
layout.setProject(project);
Layout layout= createOverlay(project, null);
layout.setPublicLayout(true);
layoutDao.add(layout);
......@@ -164,15 +156,12 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD);
Layout layout = new Layout();
layout.setProject(project);
Layout layout = createOverlay(project, null);
layout.setPublicLayout(true);
layoutDao.add(layout);
Layout curatorLayout = new Layout();
Layout curatorLayout = createOverlay(project, curator);
curatorLayout.setPublicLayout(false);
curatorLayout.setCreator(curator);
curatorLayout.setProject(project);
layoutDao.add(curatorLayout);
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
......@@ -197,15 +186,12 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
User user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD);
Layout layout = new Layout();
layout.setProject(project);
Layout layout = createOverlay(project, null);
layout.setPublicLayout(true);
layoutDao.add(layout);
Layout userLayout = new Layout();
Layout userLayout = createOverlay(project, user);
userLayout.setPublicLayout(false);
userLayout.setCreator(user);
userLayout.setProject(project);
layoutDao.add(userLayout);
MockHttpSession session = createSession(TEST_CURATOR_LOGIN, TEST_CURATOR_PASSWORD);
......@@ -227,20 +213,16 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
public void testUserShouldSeeAllPublicOverlaysAndOverlays() throws Exception {
User user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD, project);
Layout layout = new Layout();
layout.setProject(project);
Layout layout = createOverlay(project, null);
layout.setPublicLayout(true);
layoutDao.add(layout);
Layout hiddenLayout = new Layout();
hiddenLayout.setProject(project);
Layout hiddenLayout = createOverlay(project, null);
hiddenLayout.setPublicLayout(false);
layoutDao.add(hiddenLayout);
Layout userLayout = new Layout();
Layout userLayout = createOverlay(project, user);
userLayout.setPublicLayout(false);
userLayout.setCreator(user);
userLayout.setProject(project);
layoutDao.add(userLayout);
MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD);
......@@ -277,10 +259,7 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
User user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD, project);
createAdmin(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
Layout overlay = new Layout();
overlay.setProject(project);
overlay.setCreator(user);
layoutDao.add(overlay);
Layout overlay = createOverlay(project, user);
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
......@@ -298,10 +277,7 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
User curator = createCurator(TEST_CURATOR_LOGIN, TEST_CURATOR_PASSWORD);
userService.grantUserPrivilege(curator, PrivilegeType.READ_PROJECT, project.getProjectId());
Layout overlay = new Layout();
overlay.setProject(project);
overlay.setCreator(user);
layoutDao.add(overlay);
Layout overlay = createOverlay(project, user);
MockHttpSession session = createSession(TEST_CURATOR_LOGIN, TEST_CURATOR_PASSWORD);
......@@ -317,10 +293,7 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
public void testUserCanAccessHisOwnOverlay() throws Exception {
User user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD, project);
Layout overlay = new Layout();
overlay.setProject(project);
overlay.setCreator(user);
layoutDao.add(overlay);
Layout overlay = createOverlay(project, user);
MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD);
......@@ -337,10 +310,7 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD, project);
User admin = createAdmin(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
Layout overlay = new Layout();
overlay.setProject(project);
overlay.setCreator(admin);
layoutDao.add(overlay);
Layout overlay = createOverlay(project, admin);
MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD);
......@@ -922,8 +892,7 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
public void testUserCanAccessPublicOverlay() throws Exception {
createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD, project);
Layout overlay = new Layout();
overlay.setProject(project);
Layout overlay = createOverlay(project, null);
overlay.setPublicLayout(true);
layoutDao.add(overlay);
......
Supports Markdown
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