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

OverviewLink serializers implemented

parent 70104c30
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 com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.modelutils.serializer.model.map.OverviewImageLinkSerializer;
/**
* Link used in {@link OverviewImage parent OverviewImage} to link it to
......@@ -13,6 +19,7 @@ import lcsb.mapviewer.common.exception.NotImplementedException;
*/
@Entity
@DiscriminatorValue("IMAGE_LINK")
@JsonSerialize(using = OverviewImageLinkSerializer.class)
public class OverviewImageLink extends OverviewLink {
/**
......
......@@ -5,9 +5,12 @@ import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.modelutils.serializer.model.map.OverviewModelLinkSerializer;
/**
* Link used in {@link OverviewImage parent OverviewImage} to link it to
......@@ -18,6 +21,7 @@ import lcsb.mapviewer.model.map.model.ModelData;
*/
@Entity
@DiscriminatorValue("MODEL_LINK")
@JsonSerialize(using = OverviewModelLinkSerializer.class)
public class OverviewModelLink extends OverviewLink {
/**
......
......@@ -3,7 +3,10 @@ package lcsb.mapviewer.model.map;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.modelutils.serializer.model.map.OverviewSearchLinkSerializer;
/**
* Link used in {@link OverviewImage parent OverviewImage} to link it to
......@@ -14,6 +17,7 @@ import lcsb.mapviewer.common.exception.NotImplementedException;
*/
@Entity
@DiscriminatorValue("SEARCH_LINK")
@JsonSerialize(using = OverviewSearchLinkSerializer.class)
public class OverviewSearchLink extends OverviewLink {
/**
......
package lcsb.mapviewer.modelutils.serializer.model.map;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lcsb.mapviewer.model.map.OverviewImageLink;
public class OverviewImageLinkSerializer extends JsonSerializer<OverviewImageLink> {
@Override
public void serialize(final OverviewImageLink entry, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeNumberField("idObject", entry.getId());
gen.writeObjectField("polygon", entry.getPolygonCoordinates());
gen.writeNumberField("imageLinkId", entry.getLinkedOverviewImage().getId());
gen.writeStringField("type", entry.getClass().getSimpleName());
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.modelutils.serializer.model.map;
import java.awt.geom.Point2D;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lcsb.mapviewer.model.map.OverviewModelLink;
public class OverviewModelLinkSerializer extends JsonSerializer<OverviewModelLink> {
@Override
public void serialize(final OverviewModelLink entry, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeNumberField("idObject", entry.getId());
gen.writeObjectField("polygon", entry.getPolygonCoordinates());
gen.writeNumberField("zoomLevel", entry.getZoomLevel());
gen.writeObjectField("modelPoint", new Point2D.Double(entry.getxCoord(), entry.getyCoord()));
gen.writeNumberField("modelLinkId", entry.getLinkedModel().getId());
gen.writeStringField("type", entry.getClass().getSimpleName());
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.modelutils.serializer.model.map;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lcsb.mapviewer.model.map.OverviewSearchLink;
public class OverviewSearchLinkSerializer extends JsonSerializer<OverviewSearchLink> {
@Override
public void serialize(final OverviewSearchLink entry, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeNumberField("idObject", entry.getId());
gen.writeObjectField("polygon", entry.getPolygonCoordinates());
gen.writeStringField("query", entry.getQuery());
gen.writeStringField("type", entry.getClass().getSimpleName());
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.api.projects;
import java.awt.geom.Point2D;
import java.io.IOException;
import java.io.Serializable;
import java.security.MessageDigest;
......@@ -30,7 +29,6 @@ import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.OperationNotAllowedException;
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.GlyphZipEntryFile;
import lcsb.mapviewer.converter.zip.ImageZipEntryFile;
......@@ -47,8 +45,6 @@ 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;
......@@ -72,7 +68,10 @@ 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()) {
......@@ -123,7 +122,7 @@ public class ProjectRestImpl extends BaseRestImpl {
}
private Project getProjectByProjectId(String projectId) throws ObjectNotFoundException {
Project project = getProjectService().getProjectByProjectId(projectId);
Project project = getProjectService().getProjectByProjectId(projectId, true);
if (project == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist");
}
......@@ -192,44 +191,7 @@ public class ProjectRestImpl extends BaseRestImpl {
result.put("filename", image.getProject().getDirectory() + "/" + image.getFilename());
result.put("width", image.getWidth());
result.put("height", image.getHeight());
List<Map<String, Object>> links = new ArrayList<>();
for (OverviewLink link : image.getLinks()) {
links.add(overviewLinkToMap(link));
}
result.put("links", links);
return result;
}
private Map<String, Object> overviewLinkToMap(OverviewLink link) {
Map<String, Object> result = new LinkedHashMap<>();
result.put("idObject", link.getId());
result.put("polygon", polygonToMap(link.getPolygon()));
if (link instanceof OverviewModelLink) {
OverviewModelLink modelLink = (OverviewModelLink) link;
result.put("zoomLevel", modelLink.getZoomLevel());
result.put("modelPoint", new Point2D.Double(modelLink.getxCoord(), modelLink.getyCoord()));
result.put("modelLinkId", modelLink.getLinkedModel().getId());
} else if (link instanceof OverviewImageLink) {
result.put("imageLinkId", ((OverviewImageLink) link).getLinkedOverviewImage().getId());
} else if (link instanceof OverviewSearchLink) {
result.put("query", ((OverviewSearchLink) link).getQuery());
} else {
throw new NotImplementedException("Not implemented behaviour for class: " + link.getClass());
}
result.put("type", link.getClass().getSimpleName());
return result;
}
private List<Map<String, Double>> polygonToMap(String polygon) {
List<Map<String, Double>> result = new ArrayList<>();
for (String string : polygon.split(" ")) {
String tmp[] = string.split(",");
Map<String, Double> point = new TreeMap<>();
point.put("x", Double.parseDouble(tmp[0]));
point.put("y", Double.parseDouble(tmp[1]));
result.add(point);
}
result.put("links", image.getLinks());
return result;
}
......@@ -258,7 +220,7 @@ public class ProjectRestImpl extends BaseRestImpl {
}
public List<Map<String, Object>> getProjects() {
List<Project> projects = getProjectService().getAllProjects();
List<Project> projects = getProjectService().getAllProjects(true);
List<Map<String, Object>> result = new ArrayList<>();
for (Project project : projects) {
result.add(createData(project));
......@@ -447,36 +409,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);
......@@ -737,8 +699,14 @@ 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;
......
package lcsb.mapviewer.services.impl;
import java.io.*;
import java.util.*;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import javax.mail.MessagingException;
......@@ -11,33 +23,67 @@ import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LogEvent;
import org.hibernate.Hibernate;
import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.annotation.services.*;
import lcsb.mapviewer.annotation.services.MeSHParser;
import lcsb.mapviewer.annotation.services.ModelAnnotator;
import lcsb.mapviewer.annotation.services.ProblematicAnnotation;
import lcsb.mapviewer.annotation.services.TaxonomyBackend;
import lcsb.mapviewer.annotation.services.TaxonomySearchException;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator;
import lcsb.mapviewer.commands.*;
import lcsb.mapviewer.common.*;
import lcsb.mapviewer.commands.ClearColorModelCommand;
import lcsb.mapviewer.commands.CommandExecutionException;
import lcsb.mapviewer.commands.CopyCommand;
import lcsb.mapviewer.commands.CreateHierarchyCommand;
import lcsb.mapviewer.commands.SetFixedHierarchyLevelCommand;
import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.common.MinervaLoggerAppender;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.*;
import lcsb.mapviewer.converter.ColorSchemaReader;
import lcsb.mapviewer.converter.ComplexZipConverter;
import lcsb.mapviewer.converter.ComplexZipConverterParams;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.ProjectFactory;
import lcsb.mapviewer.converter.graphics.DrawingException;
import lcsb.mapviewer.converter.graphics.MapGenerator;
import lcsb.mapviewer.converter.graphics.MapGenerator.MapGeneratorParams;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.converter.zip.ZipEntryFile;
import lcsb.mapviewer.model.*;
import lcsb.mapviewer.model.IgnoredLogMarker;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectLogEntry;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.ProjectStatus;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.layout.*;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.layout.ProjectBackground;
import lcsb.mapviewer.model.map.layout.ProjectBackgroundImageLayer;
import lcsb.mapviewer.model.map.layout.ProjectBackgroundStatus;
import lcsb.mapviewer.model.map.layout.graphics.Layer;
import lcsb.mapviewer.model.map.model.*;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.map.model.ModelSubmodelConnection;
import lcsb.mapviewer.model.overlay.DataOverlay;
import lcsb.mapviewer.model.overlay.InvalidDataOverlayException;
import lcsb.mapviewer.model.user.*;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.model.user.UserAnnotationSchema;
import lcsb.mapviewer.model.user.UserClassAnnotators;
import lcsb.mapviewer.model.user.UserClassRequiredAnnotations;
import lcsb.mapviewer.model.user.UserClassValidAnnotations;
import lcsb.mapviewer.model.user.annotator.AnnotatorData;
import lcsb.mapviewer.modelutils.map.ClassTreeNode;
import lcsb.mapviewer.modelutils.map.ElementUtils;
......@@ -47,7 +93,11 @@ import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.persist.dao.map.ModelDao;
import lcsb.mapviewer.persist.dao.map.ProjectBackgroundDao;
import lcsb.mapviewer.persist.dao.user.UserDao;
import lcsb.mapviewer.services.interfaces.*;
import lcsb.mapviewer.services.interfaces.ICommentService;
import lcsb.mapviewer.services.interfaces.IConfigurationService;
import lcsb.mapviewer.services.interfaces.IModelService;
import lcsb.mapviewer.services.interfaces.IProjectService;
import lcsb.mapviewer.services.interfaces.IUserService;
import lcsb.mapviewer.services.overlay.AnnotatedObjectTreeRow;
import lcsb.mapviewer.services.search.chemical.IChemicalService;
import lcsb.mapviewer.services.search.drug.IDrugService;
......@@ -598,8 +648,8 @@ public class ProjectService implements IProjectService {
/**
* When we encountered hibernate exception we need to handle error reporting
* differently (hibernate session is broken). This method handles such case when
* hibernate exception occurred when removing project.
* differently (hibernate session is broken). This method handles such case
* when hibernate exception occurred when removing project.
*
* @param originalProject
* project that was being removed
......@@ -1247,4 +1297,26 @@ public class ProjectService implements IProjectService {
}
validator.fixValidationIssues(project);
}
@Override
public Project getProjectByProjectId(String projectId, boolean initializeLazy) {
Project result = getProjectByProjectId(projectId);
if (result != null && initializeLazy) {
for (ModelData model: result.getModels()) {
Hibernate.initialize(model);
}
}
return result;
}
@Override
public List<Project> getAllProjects(boolean initializeLazy) {
List<Project> result = getAllProjects();
for (Project project : result) {
for (ModelData model: project.getModels()) {
Hibernate.initialize(model);
}
}
return result;
}
}
......@@ -26,6 +26,8 @@ public interface IProjectService {
* doesn't exist.
*/
Project getProjectByProjectId(String projectId);
Project getProjectByProjectId(String projectId, boolean initializeLazy);
/**
* Checks if project with a given {@link Project#projectId identifier} exists.
......@@ -43,6 +45,8 @@ public interface IProjectService {
* @return list of all projects.
*/
List<Project> getAllProjects();
List<Project> getAllProjects(boolean initializeLazy);
/**
* Removes project from the system.
......
......@@ -134,7 +134,6 @@ public class ProjectControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession session = createSession(CURATOR_LOGIN, CURATOR_PASSWORD);
RequestBuilder request = get("/api/projects/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
String response = mockMvc.perform(request)
......
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