Commit 2c77b592 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

OverviewImageSerializer implemeted

parent af654ddc
......@@ -4,14 +4,25 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.modelutils.serializer.model.map.OverviewImageSerializer;
/**
* This class describes single image that overview the model. Images can create
......@@ -23,6 +34,7 @@ import lcsb.mapviewer.model.map.model.ModelData;
*
*/
@Entity
@JsonSerialize(using = OverviewImageSerializer.class)
public class OverviewImage implements Serializable {
/**
......
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.OverviewImage;
public class OverviewImageSerializer extends JsonSerializer<OverviewImage> {
@Override
public void serialize(final OverviewImage entry, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeNumberField("idObject", entry.getId());
gen.writeStringField("filename", entry.getProject().getDirectory() + "/" + entry.getFilename());
gen.writeNumberField("width", entry.getWidth());
gen.writeNumberField("height", entry.getHeight());
gen.writeObjectField("links", entry.getLinks());
gen.writeEndObject();
}
}
\ No newline at end of file
......@@ -156,12 +156,7 @@ public class ProjectRestImpl extends BaseRestImpl {
result.put("projectId", project.getProjectId());
result.put("creationDate", super.prepareDate(project.getCreationDate()));
result.put("mapCanvasType", project.getMapCanvasType());
List<Map<String, Object>> images = new ArrayList<>();
for (OverviewImage image : project.getOverviewImages()) {
images.add(imageToMap(image));
}
result.put("overviewImageViews", images);
result.put("overviewImageViews", project.getOverviewImages());
Set<OverviewImage> set = new LinkedHashSet<>();
set.addAll(project.getOverviewImages());
......@@ -173,11 +168,11 @@ public class ProjectRestImpl extends BaseRestImpl {
}
}
if (set.size() > 0) {
result.put("topOverviewImage", imageToMap(set.iterator().next()));
result.put("topOverviewImage", set.iterator().next());
} else if (project.getOverviewImages().size() > 0) {
logger.warn(
"Cannot determine top level image. Taking first one. " + project.getOverviewImages().get(0).getFilename());
result.put("topOverviewImage", imageToMap(project.getOverviewImages().get(0)));
result.put("topOverviewImage", project.getOverviewImages().get(0));
} else {
result.put("topOverviewImage", null);
}
......@@ -185,16 +180,6 @@ public class ProjectRestImpl extends BaseRestImpl {
return result;
}
private Map<String, Object> imageToMap(OverviewImage image) {
Map<String, Object> result = new LinkedHashMap<>();
result.put("idObject", image.getId());
result.put("filename", image.getProject().getDirectory() + "/" + image.getFilename());
result.put("width", image.getWidth());
result.put("height", image.getHeight());
result.put("links", image.getLinks());
return result;
}
public FileEntry getSource(String projectId) throws QueryException {
Project project = getProjectByProjectId(projectId);
if (project.getInputData() != null) {
......
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