Commit 70104c30 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

make sure that test project ctonains image links

parent 09e2b39f
package lcsb.mapviewer.model.map;
import javax.persistence.*;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.model.Model;
......@@ -85,6 +88,10 @@ public class OverviewModelLink extends OverviewLink {
}
}
public void setLinkedModel(ModelData model) {
this.linkedModel = model;
}
@Override
public OverviewModelLink copy() {
if (this.getClass() == OverviewModelLink.class) {
......
......@@ -33,9 +33,6 @@ public class OverviewModelLinkTest extends ModelTestFunctions {
@Test
public void testSetters() {
OverviewModelLink link = new OverviewModelLink();
link.setLinkedModel(null);
assertNull(link.getLinkedModel());
link.setxCoord(2.0);
link.setyCoord(3.0);
......
......@@ -3,21 +3,27 @@ package lcsb.mapviewer.api.projects;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.*;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import com.sun.istack.NotNull;
import lcsb.mapviewer.api.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.model.cache.FileEntry;
import lcsb.mapviewer.model.map.layout.ProjectBackground;
import lcsb.mapviewer.model.security.PrivilegeType;
......@@ -29,7 +35,7 @@ import lcsb.mapviewer.services.interfaces.IUserService;
@RestController
@RequestMapping(value = "/api/projects", produces = MediaType.APPLICATION_JSON_VALUE)
public class ProjectController extends BaseController {
private ServletContext context;
private ProjectRestImpl projectController;
private IUserService userService;
......@@ -162,7 +168,7 @@ public class ProjectController extends BaseController {
throws QueryException {
return projectController.getSubmapConnections(projectId);
}
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId) "
+ "or not @projectService.projectExists(#projectId)")
@GetMapping(value = "/{projectId}/backgrounds/")
......
......@@ -5,7 +5,17 @@ import java.io.IOException;
import java.io.Serializable;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -22,13 +32,23 @@ import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.zip.*;
import lcsb.mapviewer.converter.zip.GlyphZipEntryFile;
import lcsb.mapviewer.converter.zip.ImageZipEntryFile;
import lcsb.mapviewer.converter.zip.LayoutZipEntryFile;
import lcsb.mapviewer.converter.zip.ModelZipEntryFile;
import lcsb.mapviewer.converter.zip.ZipEntryFile;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectLogEntry;
import lcsb.mapviewer.model.cache.FileEntry;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.graphics.MapCanvasType;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.OverviewImage;
import lcsb.mapviewer.model.map.OverviewImageLink;
import lcsb.mapviewer.model.map.OverviewLink;
import lcsb.mapviewer.model.map.OverviewModelLink;
import lcsb.mapviewer.model.map.OverviewSearchLink;
import lcsb.mapviewer.model.map.layout.ProjectBackground;
import lcsb.mapviewer.model.map.model.SubmodelType;
import lcsb.mapviewer.model.map.species.Element;
......@@ -38,8 +58,13 @@ import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao;
import lcsb.mapviewer.persist.dao.map.species.ElementProperty;
import lcsb.mapviewer.services.*;
import lcsb.mapviewer.services.interfaces.*;
import lcsb.mapviewer.services.ObjectExistsException;
import lcsb.mapviewer.services.ObjectNotFoundException;
import lcsb.mapviewer.services.QueryException;
import lcsb.mapviewer.services.interfaces.IElementService;
import lcsb.mapviewer.services.interfaces.IProjectService;
import lcsb.mapviewer.services.interfaces.IReactionService;
import lcsb.mapviewer.services.interfaces.IUserService;
import lcsb.mapviewer.services.utils.CreateProjectParams;
@Transactional
......@@ -47,10 +72,7 @@ import lcsb.mapviewer.services.utils.CreateProjectParams;
public class ProjectRestImpl extends BaseRestImpl {
public static enum ZipEntryFileType {
MAP,
OVERLAY,
IMAGE,
GLYPH;
MAP, OVERLAY, IMAGE, GLYPH;
public static ZipEntryFileType getType(String entryType) {
for (ZipEntryFileType type : ZipEntryFileType.values()) {
......@@ -425,36 +447,36 @@ public class ProjectRestImpl extends BaseRestImpl {
throw new QueryException("Unknown type for zip entry: zip-entries[" + fileIndex + "]");
}
switch (type) {
case MAP:
String submodelTypeKey = "zip-entries[" + fileIndex + "][_data][type][id]";
String rootKey = "zip-entries[" + fileIndex + "][_data][root]";
String mappingKey = "zip-entries[" + fileIndex + "][_data][mapping]";
String mapTypeString = getStringValue(data.get(submodelTypeKey), SubmodelType.UNKNOWN.name());
SubmodelType mapType = SubmodelType.valueOf(mapTypeString);
name = (String) data.get("zip-entries[" + fileIndex + "][_data][name]").get(0);
Boolean root = getBoolValue(data.get(rootKey), false);
Boolean mapping = getBoolValue(data.get(mappingKey), false);
entry = new ModelZipEntryFile(filename, name, root, mapping, mapType);
break;
case OVERLAY:
name = getFirstEntry(data, "zip-entries[" + fileIndex + "][_data][name]");
String description = getFirstEntry(data, "zip-entries[" + fileIndex + "][_data][description]");
if (name == null || name.trim().isEmpty()) {
throw new QueryException("zip-entries[" + fileIndex + "][_data][name] cannot be empty");
}
entry = new LayoutZipEntryFile(filename, name, description);
break;
case IMAGE:
entry = new ImageZipEntryFile(filename);
break;
case GLYPH:
entry = new GlyphZipEntryFile(filename);
break;
default:
throw new QueryException("Unknown entry type: " + entryType);
case MAP:
String submodelTypeKey = "zip-entries[" + fileIndex + "][_data][type][id]";
String rootKey = "zip-entries[" + fileIndex + "][_data][root]";
String mappingKey = "zip-entries[" + fileIndex + "][_data][mapping]";
String mapTypeString = getStringValue(data.get(submodelTypeKey), SubmodelType.UNKNOWN.name());
SubmodelType mapType = SubmodelType.valueOf(mapTypeString);
name = (String) data.get("zip-entries[" + fileIndex + "][_data][name]").get(0);
Boolean root = getBoolValue(data.get(rootKey), false);
Boolean mapping = getBoolValue(data.get(mappingKey), false);
entry = new ModelZipEntryFile(filename, name, root, mapping, mapType);
break;
case OVERLAY:
name = getFirstEntry(data, "zip-entries[" + fileIndex + "][_data][name]");
String description = getFirstEntry(data, "zip-entries[" + fileIndex + "][_data][description]");
if (name == null || name.trim().isEmpty()) {
throw new QueryException("zip-entries[" + fileIndex + "][_data][name] cannot be empty");
}
entry = new LayoutZipEntryFile(filename, name, description);
break;
case IMAGE:
entry = new ImageZipEntryFile(filename);
break;
case GLYPH:
entry = new GlyphZipEntryFile(filename);
break;
default:
throw new QueryException("Unknown entry type: " + entryType);
}
fileIndex++;
result.add(entry);
......@@ -715,14 +737,8 @@ public class ProjectRestImpl extends BaseRestImpl {
}
private enum LogSortColumn {
ID("id"),
LEVEL("level"),
TYPE("type"),
OBJECT_IDENTIFIER("objectIdentifier"),
OBJECT_CLASS("objectClass"),
MAP_NAME("mapName"),
SOURCE("source"),
CONTENT("content");
ID("id"), LEVEL("level"), TYPE("type"), OBJECT_IDENTIFIER("objectIdentifier"), OBJECT_CLASS("objectClass"), MAP_NAME("mapName"), SOURCE("source"), CONTENT(
"content");
private String commonName;
......
......@@ -306,6 +306,24 @@ abstract public class ControllerIntegrationTest {
}
ModelData map = new ModelData();
OverviewModelLink link1 =new OverviewModelLink();
link1.setLinkedModel(map);
link1.setPolygon("0,0 10,10 10,0");
link1.setxCoord(10);
link1.setyCoord(20);
link1.setZoomLevel(2);
image.addLink(link1);
OverviewImageLink link2 =new OverviewImageLink();
link2.setLinkedOverviewImage(image);
link2.setPolygon("0,0 10,10 10,0");
image.addLink(link2);
OverviewSearchLink link3 =new OverviewSearchLink();
link3.setQuery("a1");
link3.setPolygon("0,0 10,10 10,0");
image.addLink(link3);
map.setName("map_name");
map.setTileSize(256);
map.setWidth(100);
......
......@@ -36,7 +36,6 @@ import org.springframework.test.web.servlet.RequestBuilder;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonParser;
import lcsb.mapviewer.model.cache.BigFileEntry;
import lcsb.mapviewer.model.map.MiriamData;
......
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